2

I'm creating a dynamic class in EclipseLink, but after created can not add a new field to my class.

When I add a new field, eclipselink creates a column in the table but when trying to set the value in this column the EntityManager can not salver and puts NULL.

How do I add a new field to my DynamicType after adding it in JPADynamicHelper?

DynamicClassLoader dcl = new DynamicClassLoader(Thread.currentThread().getContextClassLoader());

    Class<?> exClass= dcl.createDynamicClass(packagePrefix + "Example");

    JPADynamicTypeBuilder exBuilder= new JPADynamicTypeBuilder(doClass, null, "Example");

    // configure builber
    exBuilder.setPrimaryKeyFields("ID");
    exBuilder.addDirectMapping("id", int.class, "ID");
    exBuilder.addDirectMapping("name", String.class, "NAME");

    // configure descriptor
    ClassDescriptor exDescriptor = exBuilder.getType().getDescriptor();

    //configure sequence id
    exBuilder.configureSequencing("DYNAMIC_SEQ", "ID");

    // EntityManagerFactory
    emf = createEntityManagerFactory(dcl, "default");       
    JPADynamicHelper helper = new JPADynamicHelper(emf);

    //Here I add the helper type
    helper.addTypes(true, true, exBuilder.getType());

    // Create tables and relationship
    new SchemaManager(helper.getSession()).extendDefaultTables(true);


    //Adding a new field
    exBuilder.addDirectMapping("id", int.class, "ID");

    //here I add the helper again but do not add
    helper.addTypes(true, true, exBuilder.getType());

Can anyone help me?

wmews
  • 21
  • 1

1 Answers1

0

Try adding the new field before calling createEntityManagerFactory().

James
  • 17,965
  • 11
  • 91
  • 146