使用TABLE_PER_CLASS在JPA上进行二级继承

时间:2014-11-28 12:50:50

标签: java jpa inheritance eclipselink

我无法使用二级继承......

有没有人参与这个主题? 也许是暗示?

我被迫使用其他继承策略?:/

FileEntity类

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "file_entity", schema = "", catalog = Constants.CATALOG_NAME)
public class FileEntity {
...
}

文档类

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "document", schema = "", catalog = Constants.CATALOG_NAME)
public class Document extends FileEntity {
...
}

邮件类

@Entity
@Table(name = "mail", schema = "", catalog = Constants.CATALOG_NAME)
public class Mail extends Document

得到以下异常,其中没有填充的异常描述..

Descriptor Exceptions: 
Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

java.lang.NullPointerException

    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:696)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)

Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------


java.lang.NullPointerException
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareOneToOneSelectionQuery(TablePerClassPolicy.java:166)
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareSelectionQuery(TablePerClassPolicy.java:193)
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareChildrenSelectionQuery(TablePerClassPolicy.java:113)
    at org.eclipse.persistence.mappings.OneToOneMapping.initialize(OneToOneMapping.java:1176)
    at org.eclipse.persistence.descriptors.ClassDescriptor.initialize(ClassDescriptor.java:3114)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:673)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)


java.lang.NullPointerException
    at org.eclipse.persistence.mappings.ForeignReferenceMapping.isLockableMapping(ForeignReferenceMapping.java:1092)
    at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3808)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:687)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)

[EL Config]: connection: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Connection(486777790)--Thread(Thread[main,5,main])--disconnect
[EL Finer]: cache: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Thread(Thread[main,5,main])--initialize identitymaps
[EL Info]: connection: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Thread(Thread[main,5,main])--file:/C:/Users/Péter/workspace/applicLiquidator.trunk/target/classes/_liquidator logout successful
[EL Config]: connection: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Connection(1860920268)--Thread(Thread[main,5,main])--disconnect
[EL Severe]: ejb: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

java.lang.NullPointerException

    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:696)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)

Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------


java.lang.NullPointerException
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareOneToOneSelectionQuery(TablePerClassPolicy.java:166)
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareSelectionQuery(TablePerClassPolicy.java:193)
    at org.eclipse.persistence.descriptors.TablePerClassPolicy.prepareChildrenSelectionQuery(TablePerClassPolicy.java:113)
    at org.eclipse.persistence.mappings.OneToOneMapping.initialize(OneToOneMapping.java:1176)
    at org.eclipse.persistence.descriptors.ClassDescriptor.initialize(ClassDescriptor.java:3114)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:673)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)


java.lang.NullPointerException
    at org.eclipse.persistence.mappings.ForeignReferenceMapping.isLockableMapping(ForeignReferenceMapping.java:1092)
    at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3808)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:687)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)

[EL Finest]: jpa: 2014-11-28 12:40:52.183--ServerSession(2146583186)--Thread(Thread[main,5,main])--End deploying Persistence Unit liquidator; session file:/C:/Users/Péter/workspace/applicLiquidator.trunk/target/classes/_liquidator; state DeployFailed; factoryCount 1
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [liquidator] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

java.lang.NullPointerException

    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:820)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:760)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
    at liquidator.util.external.csvimport.CsvImporter.initEntityManager(CsvImporter.java:42)
    at liquidator.util.external.csvimport.CsvImporter.main(CsvImporter.java:28)
Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [liquidator] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

java.lang.NullPointerException

    at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:238)
    ... 8 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

java.lang.NullPointerException

    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:696)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    ... 6 more

1 个答案:

答案 0 :(得分:0)

您是否探测为继承表使用一个鉴别器值?,例如:

@DiscriminatorColumn(name="TYPE", 
                     discriminatorType=DiscriminatorType.STRING)  <== In the the super class
@DiscriminatorValue("FileEntity")
FileEntity 

@DiscriminatorValue("Document ")
Document