How to configure Generation strategy in Dynamic Type? [message #804339] |
Wed, 22 February 2012 14:01 |
Nabeel Ahmed Messages: 20 Registered: January 2012 |
Junior Member |
|
|
I need to create person class which have pid as auto generated column.
when i create new entity using entityManager.persist(person) method i.e.
JPADynamicTypeBuilder personBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(packageName + "Person"), null, "Person");
personBuilder.setPrimaryKeyFields("pid");
DirectToFieldMapping dfm = personBuilder.addDirectMapping("pid",int.class, "pid");
personBuilder.addDirectMapping("personName", String.class, "personName");
for (EntityType<?> jpaManagedType : entityManager.getMetamodel().getEntities()) {
Object object = newInstance(jpaManagedType.getJavaType());
Attribute<?, ?> att = jpaManagedType.getAttribute("personName");
JPAMember attMember = JPAMember.create(att, object);
attMember.set("Nabeel");
entityManager.getTransaction().begin();
entityManager.persist(object);
entityManager.getTransaction().commit();
break;
}
entityManager.close();
it insert the record but with 0 value in primary key column rather than generated value.
then i changed configuration like this, but it doesn't work. what is wrong/missing here?
JPADynamicTypeBuilder personBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(packageName + "Person"), null, "Person");
personBuilder.setPrimaryKeyFields("pid");
DirectToFieldMapping dfm = personBuilder.addDirectMapping("pid",int.class, "pid");
dfm.setIsJPAId();
dfm.getDescriptor().setSequenceNumberField(dfm.getField());
dfm.getDescriptor().setSequenceNumberName("SEQ_GEN_IDENTITY");
dfm.getDescriptor().setSequenceNumberFieldName(dfm.getFieldName());
personBuilder.addDirectMapping("personName", String.class, "personName");
|
|
|
Powered by
FUDForum. Page generated in 0.04312 seconds