Composite Primary key in JPA EclipseLink DynamicPersistence [message #1062922] |
Tue, 11 June 2013 12:01 |
Gaurav Gupta 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11032 seconds