-->
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.  [ 4 posts ] 
Author Message
 Post subject: JPA/Hibernate Polymorphism in list?
PostPosted: Thu Jan 31, 2008 7:22 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Hibernate versions (from maven):

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.5.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.1.ga</version>
</dependency>
JPA

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>



Hi

Im having trouble making the following work:

pseudo code:
Code:
?? what should go here? I dont want a seperate table for xyz..
interface xyz{

@ManyToOne
   public abstract Other getOther();

}

@entity
class xy implements xy{}

@entity
class yz implements yz{}

@entity
class other{

// can contain both xy and yz
@OneToMany(mappedBy = "other")
List myStuff<xyz>;
}

Can I actually get this to work? I've also tried making xyz as an abstract class, with no luck either.


Top
 Profile  
 
 Post subject: Re: JPA/Hibernate Polymorphism in list?
PostPosted: Thu Jan 31, 2008 10:06 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Seems to work after switching to the abstract approach. And doing this in my abstract class:

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)


This is not what I wanted, and it seems that I cant avoid the abstract class having a table..

I guess It would have worked with interface approach too if it had the same setup..

regards


Top
 Profile  
 
 Post subject: JPA Inheritance - no separate table for interface
PostPosted: Fri Feb 15, 2008 10:11 am 
Newbie

Joined: Thu Feb 14, 2008 11:47 am
Posts: 2
Hi there , i saw your post saying that you could not create an abstract class or an interface and extending or implementing it by a concrete class without the interface or either abstract class being persisted .

Did you manage to do that indeed , i saw nobody answering to your question you posted , please look here

http://forum.hibernate.org/viewtopic.ph ... nheritance

if you can please answer , regards


Top
 Profile  
 
 Post subject: Re: JPA Inheritance - no separate table for interface
PostPosted: Fri Feb 15, 2008 10:58 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
gabry wrote:
Hi there , i saw your post saying that you could not create an abstract class or an interface and extending or implementing it by a concrete class without the interface or either abstract class being persisted .

Did you manage to do that indeed , i saw nobody answering to your question you posted , please look here

http://forum.hibernate.org/viewtopic.ph ... nheritance

if you can please answer , regards


I managed to do what I stated above.. Having an abstract class/interface which is persisted to db. Which actually is okay.. The properties which are in the abstract class goes into one table and the extended stuff into another..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.