关于多对一关联的问题 Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

chengxianke 2006-08-21 09:35:12
大家好,小弟最近正在学习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

拜托各位帮我看看,到底是那方面的错误,俺调二天啦!...........


...全文
1638 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
interpb 2006-08-23
  • 打赏
  • 举报
回复
你自己试一下 不就可以了
chengxianke 2006-08-22
  • 打赏
  • 举报
回复
不可能吧,这是孙卫琴书上的一个例子啊, 她那本书上是用的mysql数据库,我是用的oracle数据库啊, 大哥你再帮我看看,到底是那方面的原因啊. 求您啦!
interpb 2006-08-22
  • 打赏
  • 举报
回复
table="ORDER" order是sql关键字

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧