I'm trying to get sequences with Dynamic Entities to work in EclipseLink and I need some help.
I'm defining my dynamic entity like the following:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
EntityManager em = emf.createEntityManager();
Session session = JpaHelper.getEntityManager(em).getServerSession();
DynamicClassLoader dcl = DynamicClassLoader.lookup(session);
Class<?> testClass = dcl.createDynamicClass("org.persistence.Test");
JPADynamicTypeBuilder test = new JPADynamicTypeBuilder(testClass, null, "TEST");
test.addDirectMapping("id", long.class, "T_ID");
test.setPrimaryKeyFields("T_ID");
test.addDirectMapping("col1", long.class, "T_COL1");
test.addDirectMapping("col2", int.class, "T_COL2");
test.addDirectMapping("col3", String.class, "T_COL3");
test.addDirectMapping("col4", String.class, "T_COL4");
test.addDirectMapping("col5", double.class, "T_COL5");
test.addDirectMapping("col6", double.class, "T_COL6");
DynamicHelper helper = new JPADynamicHelper(em);
helper.addTypes(true, true, test.getType());
I noticed that everything is created according to the specified. I tried to look for some documentation how to use the database sequences and I noticed the JPADynamicTypeBuilder.configureSequencing(Sequence, String, String) method. But I couldn't find any example on how to do it. I toyed around with this method and I end always with the default sequencing strategy, ie a table named SEQUENCE.
I tried with a pre-compiled entity using the @GeneratedValue and @SequenceGenerator and everything works fine, so it's something I'm doing wrong with the dynamic entities.
Does anyone know what I might have been doing wrong?
It seems irrelevant, but I'm telling anyway that my database is Oracle.
Thanks in advance,
Rui
I do not have the details on your Sequence object so my example is just generic but something like the following should work:
test.configureSequencing(
new NativeSequence("ORACLE_SEQ_OBJ", 1, 1),
"ORACLE_SEQ_OBJ",
"T_ID");
You can use configureSequencing method on the JPADynamicTypeBuilder to set the sequence.
Here's a good example: http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/branches/2.1/trunk/examples/jpa.employee/eclipselink.example.jpa.employee.dynamic/src/example/EmployeeDynamicMappings.java
I'm still trying to make it work with table Sequencing but it gives me an error:
Exception [EclipseLink-41] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.