Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequences with Dynamic Entities in EclipseLink

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, i.e. 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

like image 352
rpvilao Avatar asked Apr 08 '11 17:04

rpvilao


1 Answers

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");
like image 98
Gordon Yorke Avatar answered Nov 14 '22 22:11

Gordon Yorke