-->
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: using set
PostPosted: Wed Aug 12, 2009 6:28 am 
Newbie

Joined: Wed Aug 12, 2009 6:07 am
Posts: 2
Hello,

I've got general knowledge about hibernate, but I've got a problem, which is for sure pretty easy to solve by an expert.

This is a snippet of my model:

(Offer can have many OfferParts)

Code:
public class Offer {
... //the main part is the collection
   private Set parts = new HashSet();
...

public class OfferPart {
...
   private Offer offer;

...


and mapping:

Offer:
Code:
...
  <set name="parts" inverse="true" >
           <key column="part_id" on-delete="cascade" />
           <one-to-many class="OfferPart" />
        </set>
...

OfferPart:
Code:
...
   <many-to-one name="offer" class="Offer"
           column="offer_id" not-null="true" />
...



And now when I initilize my application with example data:
Code:
           Offer offer = new Offer();
      session.save(offer);
      
      OfferPart part = new OfferPart();               
      part.setOffer(offer);
      session.save(part);
      
      OfferPart part2 = new OfferPart();
                part2.setOffer(offer);
      session.save(part);


and later do smth like this:
Code:
System.out.println(offer.getParts())
and I get "[]", although I think I've added two parts to to set(with this part2.setOffer(offer)).
It isn't lazy initialization I think, becouse there aren't any exception.

Please explain it to me.


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.