-->
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: Mapping composite keys in collections: error
PostPosted: Wed Jun 16, 2004 12:54 pm 
Newbie

Joined: Fri May 14, 2004 1:33 pm
Posts: 4
Hi, all,

Is it possible to map a bidirectional relationship in a collection where the element's pk contains the parent's pk, and using cascade="all"? For the life of me, I can't make this work:

I have 2 classes

OrderInfo
serviceId (pk)
sequence (pk)

OrderInfoState
serviceId (pk)
orderInfoSequence(pk)
sequence(pk)


OrderInfo has a collection of OrderInfoStates mapped like this:

<composite-id name="id" class="pt.sgctelecom.crm.servId.ordem.SICompositeId">
_<key-property name="sequence" type="java.lang.Integer" column="sequence"/>
_<key-property name="serviceId" type="java.lang.Long" column="service_id"/>
</composite-id>

<set name="states" lazy="true" inverse="true" cascade="all" sort="unsorted" order-by="entryDate asc">
_<key>
__<column name="service_id"/>
__<column name="serviceOrder_sequence"/>
_</key>
_<one-to-many class="blah.blah2.blah3.OrderInfoState"/>
</set>

and the relationship is mapped like this on the OrderInfoState side:

<composite-id name="id" class="blah.blah2.blah3.OrderInfoStateId">
_<key-property name="orderInfoSequence" type="java.lang.Integer" column="serviceOrder_sequence"/>
_<key-property name="sequence" type="java.lang.Integer" column="sequence"/>
_<key-property name="serviceId" type="java.lang.Long" column="service_id"/>
</composite-id>

<many-to-one name="orderInfo" class="blah.blah2.blah3.OrderInfo" cascade="none" outer-join="auto" update="false" insert="false" access="property">
_<column name="service_id" not-null="true"/>
_<column name="serviceOrder_sequencia" not-null="true"/>
</many-to-one>

I'm using insert="false" update="false" because other way, hibernate will complain there are repeated columns (the "service_id" and "serviceOrder_sequence" columns, which are parte of the composite-id, and the many-to-one mapping).

I insert them as follows.

// need to get orderInfo key first, so insert it first

session.save(orderInfo);

orderState.setOrderInfo(orderInfo);
orderInfo.getStates().add(orderState);

session.flush();

Hibernate always tries to update the OrderInfoState table, instead of inserting. I get

2004-06-16 17:47:03,397 ERROR [net.sf.hibernate.impl.SessionImpl] Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)

Will anyone help me with this? Am I doing something wrong?

Thank you.


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.