我有一个有2个不同List
的课程。每个List
使用不同的类作为它的泛型类型。这些类共享相同的基类。当我尝试持久化包含两个列表的类时,我得到一个错误,解释每个子类中不存在@Eelement
注释中指定的列。但是此列存在于父类中。那么我怎么能告诉datanucleus这个列是在父类而不是子类中呢?
基类:
@PersistenceCapable(table = "Z")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public abstract class Z {
@Persistent(primaryKey = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
儿童班
@PersistenceCapable(table = "X")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public class X extends Z {
@PersistenceCapable(table = "Y")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public class Y extends Z {
我正试图坚持的课程:
@PersistenceCapable(table = "MyClass")
public class MyClass {
@Persistent(column = "id", primaryKey = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
// Specifies the FK column pointing to this object (ie. MyClass)
@Element(column = "myclass_id")
@Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "order ASC"))
private List<X> xList;
// Specifies the FK column pointing to this object (ie. MyClass)
@Element(column = "myclass_id")
@Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "order ASC"))
private List<Y> yList;
这是我尝试持久MyClass
时获得的堆栈跟踪的一部分。对于两个子类表,整个堆栈跟踪不止一次地重复相同的信息,所以我刚才提到了stackstrace的一部分:
Required columns missing from table "ipk.x" : myclass_id. Perhaps your MetaData is incorrect, or you havent enabled "datanucleus.schema.autoCreateColumns".
org.datanucleus.store.rdbms.exceptions.MissingColumnException: Required columns missing from table "ipk.x" : myclass_id. Perhaps your MetaData is incorrect, or you havent enabled "datanucleus.schema.autoCreateColumns".
at org.datanucleus.store.rdbms.table.TableImpl.validateColumns(TableImpl.java:277)
at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:3421)
at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.addClassTablesAndValidate(RDBMSStoreManager.java:3218)
at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2871)
at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:119)
at org.datanucleus.store.rdbms.RDBMSStoreManager.manageClasses(RDBMSStoreManager.java:1608)
at org.datanucleus.store.rdbms.RDBMSStoreManager.getDatastoreClass(RDBMSStoreManager.java:678)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.getDatastoreClass(RDBMSPersistenceHandler.java:88)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObject(RDBMSPersistenceHandler.java:123)
at org.datanucleus.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3489)
at org.datanucleus.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3465)
at org.datanucleus.ExecutionContextImpl.persistObjectInternal(ExecutionContextImpl.java:2031)
at org.datanucleus.ExecutionContextImpl.persistObjectWork(ExecutionContextImpl.java:1874)
at org.datanucleus.ExecutionContextImpl.persistObject(ExecutionContextImpl.java:1722)
at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:722)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:747)
at ...
答案 0 :(得分:1)
那么Z中的"myClass"
字段是做什么的?也许它应该是 BI - 方向关系的一部分?在这种情况下,应该在所有者方(List(s))指定 mappedBy 。作为双向关系的一部分是您可以在Z中使用该列来存储List关系的FK的唯一方法。
Z中也没有“order”字段(指定为List(s)的一部分),因此该部分也不起作用。