-->
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: problem persisting list with access=field with hib 3.1
PostPosted: Mon Nov 27, 2006 8:46 pm 
Newbie

Joined: Mon Jul 10, 2006 5:52 pm
Posts: 6
Location: Bay Area, California, USA
Hi, Good morning!

I am seeing a strange interaction between cglib, hibernate & what I'm trying to do in my code. My mapped object has a list member variable with access="field". I am not able to update the list with new objects. Here are the details -

mapped classes - A, B, C

A has a member variable of type B, and mapping for A has <many-to-one> B

B has a member variable of type List<C>, and mapping for B has a <list> element with <many-to-many> reference to C

C's mapping has just base java data types.

What I'm trying to do is to add new C's to B's list.

Here's what the code tries to do -

A aobj = session.open(id, A.class); <-- retrieves successfully from db
B bobj = A.getB(); // <--- retrieves successfully from db
List clist = A.getEditor().getList(); // <-- returns PersistentList
C cobj = new C();
clist.add(cobj);

session.insert(cobj); // <-- works, can see sql insert
session.update(bobj); // <-- nothing happens??? doesn't generate any sql
session.update(aobj);

The funny thing is, when I view the bobj object in eclipse, it shows up as CGLIB blah blah blah, and the list member variable is null. Somehow the list is not null when I access it through the getEditor() innerclass which returns the list.

So basically I'm trying to update the collection member of a persistent object. The object being added to the collection is being persisted with the insert but the mapping is not being saved. Its as if hibernate considers the object to be clean.

At the time of session.update(bobj) the member variable for the list bobj is still null and it says its of type cglib.....

Thanks! Everything else works beautifully.

Best Regards,

Ram


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 1:35 am 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Hello,

take a look at inverse property in mapping between B and C. It says to hibernate which side must be responsible by update the relationship. The docs below will help you to understand inverse:
http://www.hibernate.org/hib_docs/refer ... irectional
http://forum.hibernate.org/viewtopic.php?t=960412
http://forum.hibernate.org/viewtopic.php?t=954996

Hope this Helps

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 7:47 pm 
Newbie

Joined: Mon Jul 10, 2006 5:52 pm
Posts: 6
Location: Bay Area, California, USA
As far as I can tell each object is responsible for storing itself, and the insert has to be done before the update of hte referencing object.

After digging around some more I suspected the auto-commit. I had set auto-commit to true, but it turns out I needed to commit the session. At that point the update statements are generated & everything works. Phew!I won't be able to go into the auto-commit issue right away but if I find something I will bring it to the community's notice.

Thank you very much!

Hibernate rocks!!!

Ram


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.