-->
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: One-To-Many Problem
PostPosted: Mon Aug 13, 2007 8:10 am 
Newbie

Joined: Mon Aug 13, 2007 7:54 am
Posts: 2
Hello,

I have got a problem with a 1:N Relationship.

I have got two classes called Customer.java and ContactPerson.java.
-One Customer can have many ContactPersons. So I put a Set of ContactPersons into the class Customer.
-One ContactPerson can have just one Customer.
Thats why there is a Customer attribute in the ContactPerson class.

There are two Database tables: one called Customer and one called ContactPerson. In the ContactPerson-Table is a column called Customer_OID. It referenced the Customer.

In the Mapping files i wrote:

ContactPerson.hbm.xml:
-----------------------------
<many-to-one name="customer" class="customer" fetch="select">
<column name="customer_OID" not-null="true" />
</many-to-one>

Customer.hbm.xml:
-----------------------------
<set name="contactPersons" inverse="true">
<key>
<column name="customer_OID" not-null="true" />
</key>
<one-to-many class="ContactPerson" />
</set>

In Both Mapping files is default-lazy="false" set.

Well now I fetched a ContactPerson out of the Database and the Customer is fetched out too.
Thats right.

I fetched a Customer out of the Database and the proper ContactPersons are not fetched with it.

Can somebody please help and explain me what i did wrong?

I want that the ContactPersons are loaded with the proper Customer!

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 8:24 am 
Beginner
Beginner

Joined: Sat Jan 14, 2006 10:05 am
Posts: 22
Location: spb.ru
you should to "join fetch" the Customer's ContactPersons by HQL


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 8:31 am 
Newbie

Joined: Mon Aug 13, 2007 7:54 am
Posts: 2
Sorry but i didn't get it.
Is there no possibility to set an attribute in the mapping file?
You mean that i need to write the select statement in a special way?


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.