Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to configure Generation strategy in Dynamic Type?
How to configure Generation strategy in Dynamic Type? [message #804339] Wed, 22 February 2012 14:01
Nabeel Ahmed is currently offline Nabeel AhmedFriend
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");
Previous Topic:Weaver Throws ClassNotFoundException For Available Classes
Next Topic:Native ORM & EclipseLink 2.3.2 Multi-Tenancy
Goto Forum:
  


Current Time: Mon Dec 09 12:53:00 GMT 2024

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

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

Back to the top