Sequences with dynamic objects in EclipseLink

I am trying to get sequences with dynamic objects to work in EclipseLink and I need help.

I define my dynamic object as follows:

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 was created as indicated. I tried to find documentation on how to use database sequences, and I noticed the JPADynamicTypeBuilder.configureSequencing (Sequence, String, String) method. But I could not find any example on how to do this. I played with this method, and I always end with the default sequence strategy, that is, a table called SEQUENCE.

I tried with a precompiled object using @GeneratedValue and @SequenceGenerator, and everything works fine, so I'm doing something wrong with dynamic objects.

Does anyone know what I could do wrong?

It seems irrelevant, but I still say that my database is Oracle.

Thanks in advance,

Rui

+8
java dynamic sequence eclipselink entities
source share
2 answers

I have no data about your Sequence object, so my example is just general, but something like the following should work:

 test.configureSequencing( new NativeSequence("ORACLE_SEQ_OBJ", 1, 1), "ORACLE_SEQ_OBJ", "T_ID"); 
+1
source share

You can use the configureSequencing method for JPADynamicTypeBuilder to set the sequence.

Here is 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 get it to 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. 
0
source share

All Articles