Eclipselink动态持久性允许多个主键: DynamicTypeBuilder.setPrimaryKeyFields(String primarykeysField...)
但是如何通过 EntityManager.find( Entity Class , Object primaryKey)
方法找到实体对象(实例)以在复合主键的情况下查找实体(多个主键)(因为没有IdClass或EmbeddedId)动态持久性。
EclipseLink在find()操作中获取pk列表但是如果在示例中定义了复合pk键 -
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
然后 EnitityManager.find(dynamicType.getJavaClass(),list)
将采取这些论点,我是对的吗?
如果我假设正确,则EnitityManager.find()
操作将如何知道List 1st参数是username或emailId pk值(表示复合pk字段值的序列)而不是Map ({username:${username},emailId:${emailId}})
或其他DataStucture。
答案 0 :(得分:-1)
您应该可以使用带有find()操作的List。