-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: why insert parent/child data incur deleting action?
PostPosted: Mon Jan 24, 2005 3:44 am 
Newbie

Joined: Mon Jan 17, 2005 9:05 am
Posts: 17
I have 2 tables(parent/child)
TEST1(
ID NUMBER(19) not null,
NAME VARCHAR2(255),
primary key(ID)

)

TEST2(
OBJID NUMBER(19) not null,
VERSION NUMBER(10) not null,
NAME VARCHAR2(255),
primay key (OBJID, VERSION)

)

Alter table TEST2 add constraints fk foreign key (OBJID) references ID.

mappping file:
<class name="Test1" table="TEST1" >
<id name="id" type="long" column="ID">
<generator class="native" >
</generator>
</id>
<property name="name" column="NAME" type="string" />

<set name="test2s" table="TEST2" lazy="true" >
<key column="OBJID" />
<composite-element class="Test2">
<property name="version" />
<property name="fieldName" />
</composite-element>
</set>
</class>


codes between session:
Code:
     Test1 test   = new Test1();
      Test2 test2 = new Test2();
      test2.setVersion(new Integer(1));
        HashSet set = new HashSet();
      set.add(test2);
      test.setTest2s(set);
      persistenceSession.save(test);


After I run the codes,

I found that the sql query is working like this:

Hibernate: insert into TEST1 (NAME, ID) values (?, ?)
Hibernate: insert into TEST2 (OBJID, version, fieldName) values (?, ?, ?)
Hibernate: delete from TEST2 where OBJID=? and version=? and fieldName=?
Hibernate: insert into TEST2 (OBJID, version, fieldName) values (?, ?, ?)


Here the insert to table TEST2 2 times, first insert to TEST2, then delete from TEST2, then insert again! Very funny, I have only one record need to insert into TEST2. I guess after this deleting, i got the error like:
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SCS.SYS_C001786) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:458)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4105)
at weblogic.jdbc.wrapper.PreparedStatement_oracle_jdbc_driver_OraclePreparedStatement.executeBatch(Unknown Source)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)


I do not know which attribute incur this deletion action and then insert again? could anyone help?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.