关于多对一关联的问题 Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
大家好,小弟最近正在学习hibernate中的多对一关联, 出现了一些问题.我现在很是着急.不知道是那个环节出现了问题. 可上火啦. 麻烦各位大哥帮助俺看看.小弟不胜感激!
我是用的oracle数据库, 表id的生成方式是sequence
这个是customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="hibernate.po.Customer" table="CUSTOMER" schema="CHENGDB">
<id name="id" type="string">
<column name="ID" length="8" />
<generator class="sequence">
<param name="sequence">CUSTOMER_SEQ_ID</param>
</generator>
</id>
<property name="name" type="string">
<column name="NAME" length="10" not-null="true" />
</property>
<property name="address" type="string">
<column name="ADDRESS" length="10" not-null="true" />
</property>
</class>
</hibernate-mapping>
这个是customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="hibernate.po.Order" table="ORDER" schema="CHENGDB">
<id name="id" type="string">
<column name="ID" length="8" />
<generator class="sequence">
<param name="sequence">ORDER_SEQ_ID</param>
</generator>
</id>
<property name="ordername" type="string">
<column name="ORDERNAME" length="20" not-null="true" />
</property>
<!-- 设置多对一的关联-->
<many-to-one name="customer" column="customerId" class="hibernate.po.Customer"/>
</class>
</hibernate-mapping>
我所要建立的关联是 定单order与顾客customer建立的多与一关联. order表中的customerId参照customer表中的id
我又做了一个类,用来向这两个表中插入数据,
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
SessionFactory sessionfactory = new Configuration().configure()
.buildSessionFactory();
Session session = sessionfactory.openSession();
Transaction tran = session.beginTransaction();
Customer customer = new Customer();
customer.setAddress("山东");
customer.setName("明明1");
Order order = new Order();
order.setOrdername("帐号名");
order.setCustomer(customer);
session.save(customer);
session.save(order);
tran.commit();
}
结果 是: 没有执行成功 ,出错啦, 我把出错的结果贴出来啦. 麻烦各位给俺看看
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at app.Application.main(Application.java:29)
Caused by: java.sql.BatchUpdateException: ORA-00903: 表名无效
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:441)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3377)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 8 more
拜托各位帮我看看,到底是那方面的错误,俺调二天啦!...........