-->
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: How to design a @JoinTable with conditions
PostPosted: Fri Jul 08, 2011 6:33 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
I have employee, role and empRoleMap. I have mapped them together -

[code]
public class Employee {

@Id
private EmployeePK id;

@ManyToOne
@JoinTable(
schema = "PROJECT",
name = "EMP_ROLE_MAP",
joinColumns = {@JoinColumn(name = "EMP_ID"),@JoinColumn(name = "EMP_ID_KEY")},
inverseJoinColumns = {@JoinColumn(name = "ROLE_CD"),@JoinColumn(name = "ROLE_CD_KEY")}
)
private Role role;
.....
[/code]

The problem I have is that the empRoleMap has multiple records with only one record marked Active='y'. As a result if I have 5 records in the join table with one marked as active then a query on the emp table for a unique empId will give me 5 same records with the nested role object.

[b]Is there a way to give conditions to the join table or can I use some sort of inheritance to fix this.[/b]


Top
 Profile  
 
 Post subject: Re: How to design a @JoinTable with conditions
PostPosted: Fri Jul 08, 2011 9:45 am 
Newbie

Joined: Wed Feb 13, 2008 7:28 pm
Posts: 5
I'm a "newbie" also, so someone more experienced will probably get on here and tell you exactly what you need via JPA...but if all else fails, you could create a view over your EMP_ROLE_MAP table that only has active records and point your object to that instead? Just an idea.


Top
 Profile  
 
 Post subject: Re: How to design a @JoinTable with conditions
PostPosted: Fri Jul 08, 2011 11:32 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
Thanks,
If I could get the join table syntax to accept hibernate objects instead of the actual table/column names then I could try to get some sort of inheritance going which would simulate the view that you were talking about but then I haven't made too much progress.

I might end up creating a view after all ;-). Any other idea ?


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.