Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 将继承策略从InheritanceType.JOINED转换为InheritanceType.SINGLE_表时出现DuplicateMappingException_Hibernate_Jpa - Fatal编程技术网

Hibernate 将继承策略从InheritanceType.JOINED转换为InheritanceType.SINGLE_表时出现DuplicateMappingException

Hibernate 将继承策略从InheritanceType.JOINED转换为InheritanceType.SINGLE_表时出现DuplicateMappingException,hibernate,jpa,Hibernate,Jpa,问题:我有一个遗留应用程序,它包含一个抽象超类(比如说Task)和50多个子类,称为SubTask1,等等。此外,这些子类具有各种具有相同名称的字段,如文件名、用户等。此外,这些子类与一个类具有各种@manytone关系(比如属性) 现在,作为一个ORM工具,我们使用hibernate,继承策略为JOINED。现在,这些实体的查询性能非常差。因此,为了提高性能,我尝试将继承策略更改为单_表,并让hibernate生成模式 @Entity @Inheritance(strategy = Inher

问题:我有一个遗留应用程序,它包含一个抽象超类(比如说
Task
)和50多个子类,称为
SubTask1
,等等。此外,这些子类具有各种具有相同名称的字段,如
文件名
用户
等。此外,这些子类与一个类具有各种@manytone关系(比如
属性

现在,作为一个ORM工具,我们使用
hibernate
,继承策略为
JOINED
。现在,这些实体的查询性能非常差。因此,为了提高性能,我尝试将继承策略更改为单_表,并让hibernate生成模式

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
abstract public class Task {
    public String type;

    //Getters and setters
}

@Entity 
public class SubTask1 extends Task {
    public subTask1Field;
    public String user;
    public string filename;
    @ManyToOne(optional = false)
    public Property host;
    //Getters and setters

}

@Entity 
public class SubTask2 extends Task {
    public subTask2Field;

    public String user;
    public string filename;
    @ManyToOne(optional = false)
    public Property host;
    //Getters and setters

}

@Entity
public class Property {
    @Unique
    @Required
    public String name;

    @Required
    public String value;    
}
问题:在应用程序启动期间,我遇到以下异常

2020-07-09 12:18:26,665 ERROR --- [                     main] play                           :   Can't start in PROD mode with errors
javax.persistence.PersistenceException: Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
        at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:204)
        at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:616)
        at play.Play.start(Play.java:538)
        at play.Play.init(Play.java:309)
        at play.server.Server.main(Server.java:160)
Caused by: org.hibernate.DuplicateMappingException:  Table [Task] contains logical column name [fileName] referenced by multiple physical column names: [`filename`], [`fileName`]
        at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.bindLogicalToPhysical(Configuration.java:3021)
        at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.addBinding(Configuration.java:3008)
        at org.hibernate.cfg.Configuration$MappingsImpl.addColumnBinding(Configuration.java:3053)
        at org.hibernate.cfg.Ejb3Column.addColumnBinding(Ejb3Column.java:330)
        at org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:322)
        at org.hibernate.cfg.annotations.SimpleValueBinder.linkWithValue(SimpleValueBinder.java:361)
        at org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:336)
        at org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:193)
        at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
        at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2166)
        at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:895)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:728)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3625)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3579)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1381)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1786)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:918)
        ... 6 common frames omitted
Exception in thread "main" play.exceptions.UnexpectedException: Unexpected Error
        at play.Play.start(Play.java:568)
        at play.Play.init(Play.java:309)
        at play.server.Server.main(Server.java:160)
Caused by: javax.persistence.PersistenceException: Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
        at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:204)
        at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:616)
        at play.Play.start(Play.java:538)
        ... 2 more
Caused by: org.hibernate.DuplicateMappingException:  Table [Task] contains logical column name [fileName] referenced by multiple physical column names: [`filename`], [`fileName`]
        at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.bindLogicalToPhysical(Configuration.java:3021)
        at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.addBinding(Configuration.java:3008)
        at org.hibernate.cfg.Configuration$MappingsImpl.addColumnBinding(Configuration.java:3053)
        at org.hibernate.cfg.Ejb3Column.addColumnBinding(Ejb3Column.java:330)
        at org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:322)
        at org.hibernate.cfg.annotations.SimpleValueBinder.linkWithValue(SimpleValueBinder.java:361)
        at org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:336)
        at org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:193)
        at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
        at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2166)
        at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:895)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:728)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3625)
        at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3579)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1381)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1786)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:918)
        ... 6 more
2020-07-09 12:18:26665错误---[main]播放:出现错误时无法在PROD模式下启动
javax.persistence.PersistenceException:无法构建EntityManagerFactory
位于org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
位于org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
atplay.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:204)
在播放中.plugins.PluginCollection.onApplicationStart(PluginCollection.java:616)
play.play.start(play.java:538)
play.play.init(play.java:309)
at play.server.server.main(server.java:160)
原因:org.hibernate.DuplicateMappingException:表[Task]包含由多个物理列名引用的逻辑列名[fileName]:[`fileName`],[`fileName`]
位于org.hibernate.cfg.Configuration$mappingsiml$TableColumnNameBinding.bindLogicalToPhysical(Configuration.java:3021)
位于org.hibernate.cfg.Configuration$mappingsiml$TableColumnNameBinding.addBinding(Configuration.java:3008)
位于org.hibernate.cfg.Configuration$mappingsiml.addColumnBinding(Configuration.java:3053)
位于org.hibernate.cfg.Ejb3Column.addColumnBinding(Ejb3Column.java:330)
位于org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:322)
位于org.hibernate.cfg.annotations.SimpleValueBinder.linkWithValue(SimpleValueBinder.java:361)
位于org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:336)
在org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:193)上
位于org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
在org.hibernate.cfg.AnnotationBinder.processElementAnnotations上(AnnotationBinder.java:2166)
位于org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:895)
位于org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:728)
位于org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3625)
位于org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3579)
位于org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1381)
位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1786)
位于org.hibernate.ejb.EntityManagerFactoryImpl。(EntityManagerFactoryImpl.java:96)
位于org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:918)
... 省略了6个公共框架
线程“main”中出现异常play.exceptions.UnexpectedException:意外错误
play.play.start(play.java:568)
play.play.init(play.java:309)
at play.server.server.main(server.java:160)
原因:javax.persistence.PersistenceException:无法生成EntityManagerFactory
位于org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
位于org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
atplay.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:204)
在播放中.plugins.PluginCollection.onApplicationStart(PluginCollection.java:616)
play.play.start(play.java:538)
... 还有两个
原因:org.hibernate.DuplicateMappingException:表[Task]包含由多个物理列名引用的逻辑列名[fileName]:[`fileName`],[`fileName`]
位于org.hibernate.cfg.Configuration$mappingsiml$TableColumnNameBinding.bindLogicalToPhysical(Configuration.java:3021)
位于org.hibernate.cfg.Configuration$mappingsiml$TableColumnNameBinding.addBinding(Configuration.java:3008)
位于org.hibernate.cfg.Configuration$mappingsiml.addColumnBinding(Configuration.java:3053)
位于org.hibernate.cfg.Ejb3Column.addColumnBinding(Ejb3Column.java:330)
位于org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:322)
位于org.hibernate.cfg.annotations.SimpleValueBinder.linkWithValue(SimpleValueBinder.java:361)
位于org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:336)
在org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:193)上
位于org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
在org.hibernate.cfg.AnnotationBinder.processElementAnnotations上(AnnotationBinder.java:2166)
位于org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:895)
位于org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:728)
位于org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3625)
位于org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3579)
在org.hibernate.cfg.Configuration.secondPassCompile(配置。