-->
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: JoinColumn: using Parent class field
PostPosted: Wed Mar 23, 2011 5:39 am 
Newbie

Joined: Thu Mar 17, 2011 5:31 am
Posts: 7
Hi,
I have the following class structure...

Parent.java
=====================
Code:
@Entity
@Table(name="TABLE1")
@Inheritance(strategy = InheritanceType.JOINED)
abstract class Parent{

   @Column(name="ID")
   @Id
   private Integer Id;
   ...
   ...
   
   @Column(name="D_SOURCE_ID")
   private Integer dSourceId;
}


SubClass.java
======================
Code:
@Entity
@Table(name="TABLE2")
@PrimaryKeyJoinColumn(name = "ID")
class SubClass extends Parent{

   ...
   ...
             /**
             *A List of CompositeElement objects.
             *
             */
   @OneToMany(fetch = FetchType.EAGER)
   @JoinColumn( ??? )
   private List<CompositeElement> element;

}

CompositeElement.java
=====================
Code:
@Entity
@Table(name="SIGN")
class CompositeElement {
   ...
   ...
   @Column(name="C_D_SOURCE_ID");
   private Integer compDSourceId;
}


As you can see, Subclass entity is child of Parent class entity.
Inside SubClass; there is a List of 'CompositeElement' objects;
the condition is that 'CompositeElement' objects must be fetched from 'SIGN' table when (Parent.dSourceId == CompositeElement.compDSourceId).

What should i do in JoinColumn so that this can be done??!!!

Appreciate help

Regards,
Pravin


Top
 Profile  
 
 Post subject: Re: JoinColumn: using Parent class field
PostPosted: Wed Mar 23, 2011 5:54 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Is it possible to normalize you schema?

Is the column dSourceId unique? if yes, you could also join using the primary key. if not, you actually have a many-to-many relationship.

if the relationship is mapped through a property of the parent class, why don't you map the collection there?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: JoinColumn: using Parent class field
PostPosted: Wed Mar 23, 2011 6:11 am 
Newbie

Joined: Thu Mar 17, 2011 5:31 am
Posts: 7
mmerder wrote:
Is it possible to normalize you schema?

Is the column dSourceId unique? if yes, you could also join using the primary key. if not, you actually have a many-to-many relationship.

if the relationship is mapped through a property of the parent class, why don't you map the collection there?



Hi,

Normalization cannot be done, unfortunately :( . DB modification is not in my hands.

dSourceId is not unique.
There are other subclasses of the parent class, we do not want to make this list available to other subclasses.

Thanks and Regards,
Pravin


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.