-->
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: How to add ~none persistant entities to a collection
PostPosted: Wed May 03, 2006 12:56 pm 
Newbie

Joined: Wed May 03, 2006 12:48 pm
Posts: 1
Hi all, am hoping you can help.

I have a mapped entity.. for the sake of an example lets call it Customer. I have a database table called countries, and a mapping called country. I want to map a set that is a collection of all the records in the countries table of type country, but there would be no relationship between customer and country. Therefore no key to key into a set mapping. The countries would be immutable under the context of the customer object graph.


Can this be done? I have been digging the docs and also the Bauer book and also the caveat emptor stuff.. with no joy. Any help much appreicated.

Thank in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 11:04 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Can what be done? I think you've missed something. Are you trying to put a set of countries in a customer? A set of customers in a country? If you are trying one of these things, how are you hoping to do it? Will there be a foreign key from one to the other?

I'm going to guess that you want to list all customers by country. So you'd have a table like this:

Country: ID, CountryName.

And a POJO with methods getId(), getName(), and getCustomers(). In that case your mapping would be
Code:
<class name="Country" table="Country">
  <id column="ID" .../>
  <property name="Name" column="CountryName" type="string"/>
  <set name="Customers">
    <key column="ID" not-null="true"/>
    <one-to-many class="Customer"/>
  </set>
</class>

_________________
Code tags are your friend. Know them and use them.


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.