-->
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: Bidirectional polymoprh assiciation?
PostPosted: Fri Jan 13, 2006 11:48 am 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Hi there,

everthing is now working really fine for me :-) I got just one more case (i hope) to discuss.

I got an polymorphic bidirectional 1:m association between Kategorie and Produkt where Produkt is an abstract base class for Books, Videos and Cd, Cd is although abstract baseclass for MusikCd and CdRom . I implemented it as an 1:m parent/child association using an Set. That works really fine for inserting, deleting etc. as long as the Kategorie object is already in the database... If i create a new one and then a new produkt and bind them together i got an exception like : Object reference not set to an instance of an object when doing kat.Produkt.Add(produkt); if i load kat of the database its working fine...

here some code snippet:

Code:

  Produkt vid = new Video(...);
  Kategorie kat = new Kategorie(...);
 
   vid.Kategorie = kat;
   kat.Produkte.Add(vid);  // <-- Exception here...

    session.Save(kat);
    transaction.Commit();

   

I although tried to flush() the new Kategorie (so it got an Id) same for Produkt... is not working... If i use session.Load oder Get as is said, its fine...

I think it cant be a big thing, but i dont get it.

here is the mapping:



Code:
<set name="Produkte" cascade="all-delete-orphan" inverse="true" >
      <key column="KategorieId"/>
      <one-to-many class="NHTest.Produkt, NHTest"/>
      </set>
For Kategorie


And for Produkt:

Code:
<many-to-one name="Kategorie" column="KategorieId" class="NHTest.Kategorie, NHTest"/>


All Id-Generators are high-low and i did set unsave-value="0". Just in case

Thx in advance!

Regards

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 14, 2006 6:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Looks like you forgot to initialize kat.Produkte in the constructor of Kategorie.


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.