我在通过hibernate在oracle中创建表时遇到了问题。 我收到这两个错误:
Could not execute JDBC batch update
和
ORA-00942: table or view does not exist
这是我的 hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCL</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">mypass</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.default_schema">SamTest</property>
<property name="hibernate.connection.pool_size">5</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="com.sam.Teacher" />
</session-factory>
</hibernate-configuration>
教师实体
@Table(schema="SamTest")
public class Teacher {
@Id
//@GenericGenerator(name = "generator", strategy = "increment")
private int teacher_Id;
@Column
private int teacher_No;
@Column
private String teacher_Name;
@Column
private String teacher_Surname;
@Column
private String department;
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getTeacher_Id() {
return teacher_Id;
}
public void setTeacher_Id(int teacher_Id) {
this.teacher_Id = teacher_Id;
}
public int getTeacher_No() {
return teacher_No;
}
public void setTeacher_No(int teacher_No) {
this.teacher_No = teacher_No;
}
public String getTeacher_Name() {
return teacher_Name;
}
public void setTeacher_Name(String teacher_Name) {
this.teacher_Name = teacher_Name;
}
public String getTeacher_Surname() {
return teacher_Surname;
}
public void setTeacher_Surname(String teacher_Surname) {
this.teacher_Surname = teacher_Surname;
}
public Teacher() {
}
public Teacher(int teacher_No, String teacher_Name, String teacher_Surname, String department) {
this.teacher_No = teacher_No;
this.teacher_Name = teacher_Name;
this.teacher_Surname = teacher_Surname;
this.department=department;
}
}
例外
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:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.sam.RunHiber.main(RunHiber.java:23)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10500)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
答案 0 :(得分:0)
看来你在Hibernate中创建了getter和setter,但我很确定你没有创建一个表。这只是对Oracle表的引用,它显然不存在(尚未)。因此错误“表或视图不存在”。