-->
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: one-to-many with elements of different classes/tables
PostPosted: Thu Oct 20, 2005 4:01 am 
Newbie

Joined: Fri Feb 04, 2005 6:51 am
Posts: 3
Hi,

In a one-to-many Object relationship, is it possible to have the many elements belong to different classes (which are mapped to different tables) ?

For eg. consider a class called "com.foo.Transaction" mapped to the table "Transaction". Assume that this entity has a collection attribute called "lineitems". Now, the line items are of different types "com.foo.Discount", "com.foo.Item", "com.foo.Tax" etc. They have different attributes and are stored in different tables in the database. But, they all have a common superclass "com.foo.LineItem".

In this scenario, is there a way to use a single "Set" to store all the line items, and have hibernate persist them to the respective tables at runtime. I'd like to avoid having different Sets for different line item types

package com.foo;

public class Transaction {

..
..
private Set lineItems = new HashSet();

..
..

void addLineItem(LineItem lineItem) {
lineItems.add(lineItem);
}

}

Thanks
Ratheesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:53 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Yes, Hibernate can handle this. See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance for different inheritance mapping strategies.

_________________
nathan


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.