Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Question regarding JPA Joins and predicates
Question regarding JPA Joins and predicates [message #516085] Mon, 22 February 2010 12:59 Go to next message
Dominik Maehl is currently offline Dominik Maehl
Messages: 6
Registered: July 2009
Junior Member
Hello everyone,

I've recently started using JPA and EclipseLink as a provider. On our new entities everythings works like a charm. But unfortunately we have a few legacy tables and their structure is giving me a head ache when trying to map them with JPA.

Our internal authorization system uses a user, a group and a roles table.

roles can be associated to users directly or to users through a group. we have a user->group join table which is perfectly mappable through JoinTable and JoinColumns.

The problem lies in the join-table for roles to users and groups. It is one table which contains the id of the user or group in one field and the table name in another. basically it looks like this:

xx_record_id, xx_table, role_id

I'm struggling to map this in jpa. in sql i would simply say "select role_id from jointable where xx_record_id=user_id and xx_table=USERTABLE.

As I'm fairly committed to eclipselink I could live with an eclipselink specific solution as well. The only requirement I have is that lazy loading works with the roles.

I hope someone can help me. Thanks.

Dominik
Re: Question regarding JPA Joins and predicates [message #517934 is a reply to message #516085] Tue, 02 March 2010 09:59 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA does not directly support this, but this can be done in EclipseLink but using a @DescriptorCustomizer and customizing the mapping's selectionCriteria using an EclipseLink Expression.

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSele ctionCriteria

You might also be able to use a view, variable relationship, or change the database to define a join table for each relationship.


James : Wiki : Book : Blog : Twitter
Re: Question regarding JPA Joins and predicates [message #517952 is a reply to message #517934] Tue, 02 March 2010 10:31 Go to previous message
Dominik Maehl is currently offline Dominik Maehl
Messages: 6
Registered: July 2009
Junior Member
Thanks alot James,

I've scanned the documentation but that gem somehow evaded my eyes.

We've actually created two views but my dba will be happy that future problems like this are solveable more easily. I really must look a little more into the EL internals.

Dominik

Previous Topic:EclipseLinkException
Next Topic:SequenceGenerator and schema
Goto Forum:
  


Current Time: Fri Aug 01 09:57:29 EDT 2014

Powered by FUDForum. Page generated in 0.01741 seconds