-1

Eclipselink Dynamic Persistence 允许多个主键 DynamicTypeBuilder.setPrimaryKeyFields(String primarykeysField...)

但是,在 Dynamic PersistenceEntityManager.find( Entity Class , Object primaryKey)中的复合主键(Multiple 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 。

4

1 回答 1

-1

您应该能够将 List 与 find() 操作一起使用。

于 2013-06-11T13:26:43.493 回答