-->
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: Mapping @OneToMany to a super class
PostPosted: Sat Aug 05, 2006 11:17 am 
Newbie

Joined: Sat Aug 05, 2006 10:53 am
Posts: 1
I have something like the following code snippets.


@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class JobOrder implements Serializable{
@Id
public String Id;
@ManyToOne
public Occupation occupation;

....
}

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class TechnicalJobOrder extends JobOrder{

}

@Entity
public class Occupation implements Serializable{
@OneToMany(mappedBy="occupation")
List<TechnicalJobOrder> jobOrders;
...
}

The problem that I am having is that in the class Occupation, hibernate tries to map the OneToMany relationship to TechnicalJobOrder.occupation - which does not exist, and consequently creates a field in the database that is always null. I would like to be able to map this relationship to the super class JobOrder.occupation but still retrieve a TechnicalJobOrder when I iterate through the list. For right now, I have changed JobOrder to be a @MappedSuperclass and this fixes my problem, however it is not the ideal solution for me as I would also like to be able to retrieve all the JobOrders in the system at once. Is there a simple way to do what I am trying to accomplish?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 4:46 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Put the mapping information about JobOrder-Occupation into Occupation - if the jobOrder id's are consistent with db and your objects you should always get only TechnicalJobOrders into Occupation.


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.