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:
|