-->
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.  [ 2 posts ] 
Author Message
 Post subject: HELP: Update problem
PostPosted: Wed Mar 24, 2010 11:23 am 
Newbie

Joined: Wed Mar 24, 2010 11:13 am
Posts: 1
Hello to everybody!

I've got the following problem and I hope that somebody is able to give me a hint how to solve it:

There are two domain objects Product and Keyword. They are joined as one-2-many (one product can have many keywords):

//slice of Product.hbm.xml:
<set name="keywords" lazy="false" inverse="true" fetch="subselect" order-by="name" cascade="all">
<key >
<column name="customerId" />
<column name="productId" />
</key>
<one-to-many class="....Keyword"/>
</set>

Keyword has a composite-id containing four attributes.

The problem is, assuming that I've one product-object with one keyword, when I do some modification on one field of the composite-Key of the keyword and after that I save the product-object, I still get two keywords corresponding to the product-object in the database. One with the "old" composite-key, and one with the modificated one. I can guarantee, that the product Object contains only one keyword before saving.

I know, it's not the finest way to do modifications on key-fields. But in this case it is necessary. How can I tell hibernate to simply update the existing keyword and not to keep the "old" one?

I dont wanna delete every corresponding keyword before saving the product...


Best regards
roman


Top
 Profile  
 
 Post subject: Re: HELP: Update problem
PostPosted: Wed Mar 24, 2010 2:37 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It is not possible to change the primary key of an entity. This usually results in an exception. I don't know why this doesn't happen in your case. The proper way is to delete the old keyword and then insert the new one.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.