-->
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.  [ 3 posts ] 
Author Message
 Post subject: Non-Mandatory property for a many-to-many relation
PostPosted: Wed Mar 09, 2005 4:44 am 
Newbie

Joined: Tue Jan 04, 2005 9:22 am
Posts: 8
Dears,

I have some attributes on a many-to-many relation (viewDate), so I am using composite in my set. But, as you see in the following, the attribute(viewDate) is not mandatory! so, it is null when, we create it. But, when I am updating this set, It can not delete the related old row, therfore I get a duplicate error (I have created an unique constraint for this relation in the database).

Is it possible to use non-mandatory property in my composite?

With regards,
Masoud.

Hibernate version:
2.1.6

Mapping documents:
<class name="Post14" table="T14_POSTS">
...
<set name="postalBags" cascade="all" inverse="false" table="T14_POSTAL_BAG">
<key column="POST_ID" />
<composite-element class="PostalBag14">
<many-to-one
name="person"
not-null="true"
column="PERSON_ID"
/>
<property
name="viewDate"
type="java.sql.Timestamp"
not-null="false"
column="VIEW_DATE"
/>
</composite-element>
</set>
...
</class>

Code between sessionFactory.openSession() and session.close():
Transaction tx = ses.beginTransaction();
Post14 post = (Post14) ses.get(Post14.class, new Long(1));
Set children = post.getPostalBags();
Iterator it = children.iterator();
int i = 1;
while(it.hasNext()){
PostalBag14 pb14 = (PostalBag14)it.next();
pb14.setName("New Null" + i++);
}
tx.commit();
ses.flush();


Full stack trace of any exception that occurs:
java.sql.BatchUpdateException: ORA-00001: unique constraint (GAM.AK_BAG_PERSON_CONST) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:380)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8768)
at com.evermind.sql.FilterStatement.executeBatch(FilterStatement.java:410)
at com.evermind.sql.FilterStatement.executeBatch(FilterStatement.java:410)
at com.evermind.sql.FilterStatement.executeBatch(FilterStatement.java:410)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2374)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)

Name and version of the database you are using:
Database: Oracle 10g
Application Server: OC4J

The generated SQL (show_sql=true):
Hibernate: delete from T14_POSTAL_BAG where POST_ID=? and PERSON_ID=? and VIEW_DATE=?
Hibernate: insert into T14_POSTAL_BAG (POST_ID, PERSON_ID, VIEW_DATE) values (?, ?, ?)
Hibernate: insert into T14_POSTAL_BAG (POST_ID, PERSON_ID, VIEW_DATE) values (?, ?, ?)

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Re: Non-Mandatory property for a many-to-many relation
PostPosted: Wed Mar 09, 2005 4:58 am 
Newbie

Joined: Tue Jan 04, 2005 9:22 am
Posts: 8
If I create a new Set and replace it with the old one, when I call flush() over the session, hibernate uses its sqlDeleteString (delete from T14_POSTAL_BAG where POST_ID=?) and then inserts all records. But, when I just update the bound set (hibernate one) it uses sqlDeleteRowString that does not match the null related row and makes the unique constraint error.


Top
 Profile  
 
 Post subject: Re: Non-Mandatory property for a many-to-many relation
PostPosted: Thu Mar 10, 2005 2:57 am 
Newbie

Joined: Tue Jan 04, 2005 9:22 am
Posts: 8
Dears,

First of all, I should thank Gavin for his nice reference and also those guys here who answer user question. Based on what Gavin has written in hibernate_reference, I replace <set> with <idbag>, therefore I can have a composite-element with nullable properties. So, it works nice.

Cheers,
Masoud


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

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.