-->
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: "Polymorphic" Queries
PostPosted: Thu Jul 20, 2006 11:58 am 
Newbie

Joined: Wed Jul 19, 2006 9:46 am
Posts: 5
A newbies question:

I have a table, which maps to different Subclasses of a Abstract Class depending on the value of a type field in the table.

How would i map that table to the Subclasses in Hibernate?
And how would query them?

Example: different types of deductibles, which are held in the same table and have more or less the same data, but are calculated differently.

The rules are fairly static and therefore not eternalized.


Any input is appreciated.
Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 5:42 pm 
Newbie

Joined: Wed Jul 19, 2006 9:46 am
Posts: 5
I searched the documentation and other stuff.
With Java 1.5 Annotations this seems to be a non-issue. This strategie fits nicely:

Code:
@Entity(accessType=FIELD)
@Inheritance(strategy=SINGLE_TABLE)
public class File {
@Idprivate String name;
@ManyToOneprivate Folder parent;
...
}
@Entity
@Inheritance(discriminator-value=ā€œFā€)
public class Folder extends File {
...
}
@Entity(accessType=FIELD)
@Inheritance(discriminator-value=ā€œDā€)
public class Document extends File {
private long size;


Cool. This would solve my problem. But i am stuck with 1.4.x.
Now i am wondering if the same can be specified with hbm.xml?
Probably.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 6:21 pm 
Newbie

Joined: Wed Jul 19, 2006 9:46 am
Posts: 5
Well i should have read the documentation first ;-(
For a discussion of Inheritance Mapping and strategies to take see:

http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html


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.