qiaoyongjun888
2011-02-22 15:36 阅读 292
已采纳

急:SSH+Oracle||用hibernate进行多对多关系映射 出错 违反唯一性约束 奇怪

Oracle 9i,使用hibernate,多对多的关系映射,级联操作的时候,出错了.
我的数据库中表的主键是采用自增长的方式,序列+触发器进行的自增长.
实体类与表的映射文件,如下
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">





F1









<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">










JAVA代码
Configuration c=new Configuration().configure();
SessionFactory sf=c.buildSessionFactory();
Session s=sf.openSession();
s.beginTransaction();
Favorite fav=new Favorite();
fav.setFdesc("asdf");
fav.setFname("sina");
fav.setFuri("www.sina.com");
Tag tag1=new Tag();
tag1.setTname("news");
tag1.getFs().add(fav);
fav.getTaglist().add(tag1);
s.save(fav);
s.getTransaction().commit();

s.close();

错误提示:
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2242)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at entity.Tt.main(Tt.java:28)
Caused by: java.sql.BatchUpdateException: ORA-00001: 违反唯一约束条件 (SCOTT.SYS_C003139)

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 15 more
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    chenxiang105 chenxiang105 2011-02-22 18:52


    不是要配置rfid么 怎么跑出个name来关联了 未必用name做的关联

    错误信息是指的你的配置文件中的关联关系错了,所以重点看你的<many-to-*

    点赞 评论 复制链接分享

相关推荐