-->
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: Hibernate behaviour with many-to-many relations
PostPosted: Fri Jul 30, 2004 11:11 am 
Newbie

Joined: Tue Mar 30, 2004 1:06 pm
Posts: 4
Hi all.
I am facing a behaviour with Hibernate that I don't fully understand.
Given this basic client code:

Code:
1. SessionFactory sf = config.buildSessionFactory();
2. Session sess = sf.openSession();
3. Transaction tx = null;
4. CD cd = new CD(); //CD is a basic POJO

// ... set some properties on the POJO

// CD and ARTIST tables have a m2m relationship (NO inverse)
// The List "artists" has been previously populated
5. cd.setArtists(artists)

6. tx = sess.beginTransaction();
7. sess.save(cd);
8. tx.commit();
9. sess.close();

10. long id = cd.getID();
11. sess = sf.openSession();
12. CD cdx = (CD)sess.get(CD.class,new Long(id));
13. System.err.println(cdx.getArtists().size()); //This call fails, because  getArtists is null.
14. sess.close();     


What happen here is that the ARTIST table is not populated, because the inverse attribute is set to false. So, this piece of code is ok.

But, if I remove lines 6 and 8 (the tx calls), line 13 doesn't raise an exception, even if the ARTIST table and the ARTIST_CD table are not populated.

Can someone of you guys explain me this behaviour?

Thanks,
Luciano


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.