org.hibernate.AssertionFailure: Table medici.person 未找到
org.hibernate.AssertionFailure: Table medici.person not found
我正在创建一个名为 Person 的抽象 class,我从 Person 创建了两个具体的 classes,分别称为 Employee 和 Customer,我使用的是 JPA 2.1 和 Hibernate 5.3,但是当我运行 Wildfly 10 我收到以下错误。我尝试了很多但没有成功,在网上找不到任何帮助,也许在这里我能找到。我也会post三个classes.
这是人Class
package com.medici.general.entity;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
@SuppressWarnings("serial")
@Entity
@Table(name="person", schema="medici")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="per_type", discriminatorType=DiscriminatorType.INTEGER)
public class Person extends Base {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="per_id", unique=true, nullable=false)
private Integer id;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="per_situation", nullable=false)
private Register situation;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="per_type", nullable=false, updatable=false, insertable=false)
private Register type;
@OneToMany(mappedBy="person", fetch=FetchType.EAGER)
@Column(name="per_address", nullable=false)
private List<Address> addresses;
@Temporal(value=TemporalType.DATE)
@Column(name="per_creation_date", nullable=false)
private Date creationDate;
@Version
@Temporal(TemporalType.TIMESTAMP)
@Column(name="per_last_update", nullable=false)
private Date lastUpdate;
@Column(name="per_user", nullable=false)
private String User;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Register getSituation() {
return situation;
}
public void setSituation(Register situation) {
this.situation = situation;
}
public Register getType() {
return type;
}
public void setTipo(Register type) {
this.type = type;
}
public List<Address> getAddresses() {
return addresses;
}
public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
public Date getCreationDate() {
return dataCriacao;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}
这是员工 Class
package com.medici.general.entity;
import java.beans.Transient;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@SuppressWarnings("serial")
@Entity
@DiscriminatorValue("1")
@PrimaryKeyJoinColumn(name = "emp_id")
public class Employee extends Person {
@Column(name="emp_sin", unique=true, nullable=false)
private Integer sin;
@Column(name="emp_name", nullable=false)
private String name;
@Column(name="emp_lastname", nullable=false)
private String lastname;
@Column(name="emp_date_birth", nullable=false)
private Date dateBirth;
@Column(name="emp_telephone", nullable=true)
private Integer dateBirth;
@Column(name="emp_mobile", nullable=true)
private Integer mobile;
@Column(name="emp_email", nullable=true)
private String email;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="emp_sex", nullable=false, foreignKey=@ForeignKey(name="fk_sex"))
private Register sex;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="emp_martial_status", nullable=false, foreignKey=@ForeignKey(name="fk_martial_status"))
private Register martialStatus;
public Integer getSin() {
return sin;
}
public void setSin(Integer sin) {
this.sin = sin;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getDateBirth() {
return dateBirth;
}
public void setDateBirth(Date dateBirth) {
this.dateBirth = dateBirth;
}
public Integer getTelephone() {
return telephone;
}
public void setTelephone(Integer telephone) {
this.telephone = telephone;
}
public Integer getMobile() {
return mobile;
}
public void setMobile(Integer mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Register getSex() {
return sex;
}
public void setSex(Register sex) {
this.sex = sex;
}
public Register getMartialStatus() {
return martialStatus;
}
public void setMartialStatus(Register martialStatus) {
this.martialStatus = martialStatus;
}
@Transient
@Override
public String toString() {
return this.getSin() + " - " + this.getName() + " " + this.getLastName();
}
}
这是我遇到的控制台错误。
12:29:06,369 WARN [org.hibernate.cfg.AnnotationBinder] (ServerService Thread Pool -- 58) HHH000457: Joined inheritance hierarchy [com.medici.general.entity.Person] defined explicit @DiscriminatorColumn. Legacy Hibernate behavior was to ignore the @DiscriminatorColumn. However, as part of issue HHH-6911 we now apply the explicit @DiscriminatorColumn. If you would prefer the legacy behavior, enable the `hibernate.discriminator.ignore_explicit_for_joined` setting (hibernate.discriminator.ignore_explicit_for_joined=true)
12:29:06,778 ERROR [org.hibernate.AssertionFailure] (ServerService Thread Pool -- 58) HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table medici.person not found
12:29:06,779 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 58) MSC000001: Failed to start service jboss.persistenceunit."Medici.war#mediciPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Medici.war#mediciPU": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:154)
... 7 more
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:346)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 9 more
Caused by: org.hibernate.AssertionFailure: Table medici.person not found
at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5107)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:433)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
... 13 more
12:29:06,784 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "Medici.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"Medici.war#mediciPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Medici.war#mediciPU\": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
Caused by: org.hibernate.AssertionFailure: Table medici.person not found"}}
12:29:06,871 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "Medici.war" (runtime-name : "Medici.war")
12:29:06,874 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.persistenceunit."Medici.war#mediciPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Medici.war#mediciPU": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
如果您从 Person class.
中删除 schema="medici",您的代码就可以工作(减去很多拼写错误)
无论如何,在此处放置架构并不是最佳做法,因此我建议将其删除。如果您的项目使用多个模式,更好的方法是在 persistence.xml 中设置两个不同的持久性单元,然后根据您使用的模式调用不同的实体管理器。
我正在创建一个名为 Person 的抽象 class,我从 Person 创建了两个具体的 classes,分别称为 Employee 和 Customer,我使用的是 JPA 2.1 和 Hibernate 5.3,但是当我运行 Wildfly 10 我收到以下错误。我尝试了很多但没有成功,在网上找不到任何帮助,也许在这里我能找到。我也会post三个classes.
这是人Class
package com.medici.general.entity;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
@SuppressWarnings("serial")
@Entity
@Table(name="person", schema="medici")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="per_type", discriminatorType=DiscriminatorType.INTEGER)
public class Person extends Base {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="per_id", unique=true, nullable=false)
private Integer id;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="per_situation", nullable=false)
private Register situation;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="per_type", nullable=false, updatable=false, insertable=false)
private Register type;
@OneToMany(mappedBy="person", fetch=FetchType.EAGER)
@Column(name="per_address", nullable=false)
private List<Address> addresses;
@Temporal(value=TemporalType.DATE)
@Column(name="per_creation_date", nullable=false)
private Date creationDate;
@Version
@Temporal(TemporalType.TIMESTAMP)
@Column(name="per_last_update", nullable=false)
private Date lastUpdate;
@Column(name="per_user", nullable=false)
private String User;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Register getSituation() {
return situation;
}
public void setSituation(Register situation) {
this.situation = situation;
}
public Register getType() {
return type;
}
public void setTipo(Register type) {
this.type = type;
}
public List<Address> getAddresses() {
return addresses;
}
public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
public Date getCreationDate() {
return dataCriacao;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}
这是员工 Class
package com.medici.general.entity;
import java.beans.Transient;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@SuppressWarnings("serial")
@Entity
@DiscriminatorValue("1")
@PrimaryKeyJoinColumn(name = "emp_id")
public class Employee extends Person {
@Column(name="emp_sin", unique=true, nullable=false)
private Integer sin;
@Column(name="emp_name", nullable=false)
private String name;
@Column(name="emp_lastname", nullable=false)
private String lastname;
@Column(name="emp_date_birth", nullable=false)
private Date dateBirth;
@Column(name="emp_telephone", nullable=true)
private Integer dateBirth;
@Column(name="emp_mobile", nullable=true)
private Integer mobile;
@Column(name="emp_email", nullable=true)
private String email;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="emp_sex", nullable=false, foreignKey=@ForeignKey(name="fk_sex"))
private Register sex;
@OneToOne(fetch=FetchType.EAGER)
@JoinColumn(name="emp_martial_status", nullable=false, foreignKey=@ForeignKey(name="fk_martial_status"))
private Register martialStatus;
public Integer getSin() {
return sin;
}
public void setSin(Integer sin) {
this.sin = sin;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getDateBirth() {
return dateBirth;
}
public void setDateBirth(Date dateBirth) {
this.dateBirth = dateBirth;
}
public Integer getTelephone() {
return telephone;
}
public void setTelephone(Integer telephone) {
this.telephone = telephone;
}
public Integer getMobile() {
return mobile;
}
public void setMobile(Integer mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Register getSex() {
return sex;
}
public void setSex(Register sex) {
this.sex = sex;
}
public Register getMartialStatus() {
return martialStatus;
}
public void setMartialStatus(Register martialStatus) {
this.martialStatus = martialStatus;
}
@Transient
@Override
public String toString() {
return this.getSin() + " - " + this.getName() + " " + this.getLastName();
}
}
这是我遇到的控制台错误。
12:29:06,369 WARN [org.hibernate.cfg.AnnotationBinder] (ServerService Thread Pool -- 58) HHH000457: Joined inheritance hierarchy [com.medici.general.entity.Person] defined explicit @DiscriminatorColumn. Legacy Hibernate behavior was to ignore the @DiscriminatorColumn. However, as part of issue HHH-6911 we now apply the explicit @DiscriminatorColumn. If you would prefer the legacy behavior, enable the `hibernate.discriminator.ignore_explicit_for_joined` setting (hibernate.discriminator.ignore_explicit_for_joined=true)
12:29:06,778 ERROR [org.hibernate.AssertionFailure] (ServerService Thread Pool -- 58) HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table medici.person not found
12:29:06,779 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 58) MSC000001: Failed to start service jboss.persistenceunit."Medici.war#mediciPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Medici.war#mediciPU": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.run(PersistenceUnitServiceImpl.java:154)
... 7 more
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:346)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 9 more
Caused by: org.hibernate.AssertionFailure: Table medici.person not found
at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5107)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:433)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
... 13 more
12:29:06,784 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "Medici.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"Medici.war#mediciPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Medici.war#mediciPU\": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
Caused by: org.hibernate.AssertionFailure: Table medici.person not found"}}
12:29:06,871 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "Medici.war" (runtime-name : "Medici.war")
12:29:06,874 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.persistenceunit."Medici.war#mediciPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Medici.war#mediciPU": javax.persistence.PersistenceException: [PersistenceUnit: mediciPU] Unable to build Hibernate SessionFactory
如果您从 Person class.
中删除 schema="medici",您的代码就可以工作(减去很多拼写错误)无论如何,在此处放置架构并不是最佳做法,因此我建议将其删除。如果您的项目使用多个模式,更好的方法是在 persistence.xml 中设置两个不同的持久性单元,然后根据您使用的模式调用不同的实体管理器。