最近在学习SSH,数据库用的是oracle10G,这是我看马士兵的视频后,自己敲的代码跑出了这个错误求高手指点数据库表结构为:id(主键),name,age
student.hbm.xml内容为:
<class name="Student" table="student">
<id name="id" column="id"></id>
<property name="name" column="name"></property>
<property name="age" column="age"></property>

</class>Hibernate: insert into student (name, age, id) values (?, ?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1215)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:382)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.lxc.hibernate.test.StudentTest.main(StudentTest.java:22)
Caused by: java.sql.BatchUpdateException: ORA-00942: 表或视图不存在 at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more

解决方案 »

  1.   

     insert into student (name, age, id) values (?, ?, ?)
    里面这个id是否和另外的表有主外键关键约束,也就是说你这个id也许在和他关系的表没有这个id
      

  2.   

    Caused by: java.sql.BatchUpdateException: ORA-00942: 表或视图不存在检查下数据库表
    或者直接在数据库执行insert into student (name, age, id) values (?, ?, ?)看能不能成功。
      

  3.   


    因为是刚学习SSH,所以只有一个表,没有那么复杂的关系,而且用sql在控制台能把数据插进去
      

  4.   

    错误提示已经打印出来了。
    ORA-00942: 表或视图不存在建议:
    1、检查下拼写。
    2、检查数据库连接。看看登录用户是否有访问权限,用户名设置是否正确。
      

  5.   


    在控制台有sql是能插进去的,刚刚插进去。
      

  6.   

    看看你HIbernate.cfg.xml(applicationContext.xml)文件中的数据库配置Driver_class后面的数据库实例对象没有写错吧?