我在 EclipseLink 中创建一个动态类,但创建后无法向我的类添加新字段。
当我添加一个新字段时,eclipselink 在表中创建一个列,但是当尝试在此列中设置值时,EntityManager 无法保存并设置为 NULL。
在 JPADynamicHelper 中添加新字段后,如何向我的 DynamicType 添加新字段?
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());
谁能帮我?