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] @ManyToOne relation problem
PostPosted: Tue Apr 14, 2009 9:44 am 
Newbie

Joined: Tue Apr 14, 2009 9:32 am
Posts: 3
Hibernate version: Hibernate Annotations 3.4.0 GA

Name and version of the database you are using: Oracle 10i



Hi,

I have a dilemma:

+ I have 2 entities with a ManyToOne relationship and no unique ids (Embedded ids):

Entity A (date, field1, field2)
Entity B (field1, field2, startDate, endDate)

+ Primary key of Entity B is an embedded id composed by field1, field2, and startDate.

+ Relationship between EntityA and EntityB

SELECT EntityB.*
FROM EntityA, EntityB
WHERE EntityB.field1 = EntityA.field1
AND EntityB.field2 = EntityA.field2
AND EntityB.startDate <= EntityA.date
AND EntityB.endDate > EntityA.date

It always return an unique row.

=> Is it possible to establish the relationship between EntityA and Entity B with JPA annotations to fetch EntityA rows or I need to use a JPQL query to make the join ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 9:51 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
I think you are looking for @JoinColumns annotation.
http://lia.deis.unibo.it/Courses/Tecnol ... lumns.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 10:03 am 
Newbie

Joined: Tue Apr 14, 2009 9:32 am
Posts: 3
I'm not able to do that with @JoinColumns because I can't specify a condition clause in @JoinColumn annotation.

Ex: I can't specify EntityB.startDate <= EntityA.date


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 10:44 am 
Newbie

Joined: Tue Apr 14, 2009 9:32 am
Posts: 3
Maybe there is no other solution that using NamedQuery to do that ?


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.