-->
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: [JPA] CollectionOfElements and EntityManager.merge - BUG?
PostPosted: Thu Mar 06, 2008 11:31 am 
Newbie

Joined: Thu Apr 27, 2006 4:56 am
Posts: 12
I have a user class with this property

@CollectionOfElements(fetch = FetchType.EAGER)
private Set<String> buddies;

I've chosen to use CollectionOfElements to avoid detachment problems and lazy initialization exception: this is a client server application where I have to continously exchange data and it was simpler to 'cut' the model a bit in order not to have too big graphs of object when moving things, or having to deal with lazy initialization exceptions and the like.

The problem is that I've encountered a bug with Hibernate and CollectionOfElements handling.

When I merge back an updated detached instance back to hibernate using EntityManager.merge, the instance gets correctly updated (the version property and simple properties are updated), but the linked tabled USERS_BUDDIES for the buddies CollectionOfElements property DO NOT GET UPDATED AT ALL.

Pseudo code:

// Load user (user with NO buddies)
User user = em.load(id);

// DETACH IT BY SENDING IT TO CLIENT

// Add a buddy
user.getBuddies().add(buddyId);

// SEND IT BACK TO SERVER

// merge updated entity with a buddy, back to server
em.merge(user);


RESULT: USERS_BUDDIES list is still empty, and when I load back the user after the session has been closed, I get back a user with the correct updated version, but with NO buddies.

Am I doing something wrong? Is this a known bug? How Can I avoid it, if possble?

I've tried deleting and re-adding the instance (remove/persist) but it doesn't work if user has constraints on it because of other tables.

Thanks in advance for any help

P.s. using both Postgresql and Derby, problems is the same with both DBs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 7:51 am 
Newbie

Joined: Thu Apr 27, 2006 4:56 am
Posts: 12
I've checked, and it seems to happen only with derby.

PostgreSQL correctly cascades the update operation to the join table for the CollectionOfElements, while Derby does not.

Can anyone help me understand what's happening and why? :)


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.