Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Composite Primary key in JPA EclipseLink DynamicPersistence
Composite Primary key in JPA EclipseLink DynamicPersistence [message #1062922] Tue, 11 June 2013 12:01 Go to next message
Gaurav Gupta is currently offline Gaurav GuptaFriend
Messages: 9
Registered: June 2013
Location: India
Junior Member
Eclipselink Dynamic Persistence allow multiple primary key by DynamicTypeBuilder.setPrimaryKeyFields(String primarykeysField...)

but how can i find entity object(instance) by EntityManager.find( Entity Class , Object primaryKey) method to find entity in case of composite primary key(Multiple Primarykey) (because of no IdClass or EmbeddedId) in Dynamic Persistence .


EclipseLink take List of pk in the find() operation but if composite pk key defined in example -
Entity => Person
Fields => [username,emailId,firstName,lastName]
Composite PK => [username,emailId]
Class<?> clazz = new DynamicClassLoader(Thread.currentThread().getContextClassLoader()).createDynamicClass("Person");
DynamicTypeBuilder builder = new DynamicTypeBuilder(clazz, null, "Person");
DynamicType dynamicType = builder.getType();
builder.setPrimaryKeyFields(["username","emailId"]);
builder.addDirectMapping("username",String.class,"username");
builder.addDirectMapping("emailId",String.class,"emailId");
builder.addDirectMapping("firstName",String.class,"firstName");
builder.addDirectMapping("lastName",String.class,"lastName");


List list = new ArrayList();
list.add(${username}); //Run time value
list.add(${emailId}); //Run time value

then EnitityManager.find(dynamicType.getJavaClass(),list) will take these arguments , is i am right?

If i am assuming correct then how will EnitityManager.find() operation will know that List 1st argument is username or emailId pk value (means sequence of composite pk fields value) instead of Map ({username:${username},emailId:${emailId}}) or other DataStucture .

[Updated on: Tue, 11 June 2013 14:32]

Report message to a moderator

Re: Composite Primary key in JPA EclipseLink DynamicPersistence [message #1062982 is a reply to message #1062922] Tue, 11 June 2013 15:10 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The order must be the same order as your field passed to setPrimaryKeyFields().

James : Wiki : Book : Blog : Twitter
Re: Composite Primary key in JPA EclipseLink DynamicPersistence [message #1063012 is a reply to message #1062982] Tue, 11 June 2013 18:59 Go to previous message
Gaurav Gupta is currently offline Gaurav GuptaFriend
Messages: 9
Registered: June 2013
Location: India
Junior Member
Thanks for all your help . That solved my problem Smile
Previous Topic:Paid Support
Next Topic:Please vote to publish standard JPA 2.0 & 2.1 jars to Maven
Goto Forum:
  


Current Time: Tue Apr 16 22:18:53 GMT 2024

Powered by FUDForum. Page generated in 2.90548 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top