2016-06-21 7 views
0

私はPersonという抽象クラスを作成しています.Personalから2つのConcreteクラスを作成します。従業員と顧客と呼ばれ、JPA 2.1とHibernate 5.3を使用しています。私はWildfly 10を実行します。次のエラーが表示されます。私は多くのことを試みましたが、成功しなかったので、オンラインで助けを見つけることができませんでした、ここで私は見つけることができます。私は3つのクラスも投稿します。ここでorg.hibernate.AssertionFailure:テーブルのmedici.personが見つかりません

はここで人クラス

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; 
    } 
} 

は、従業員クラスは、ここで

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, [email protected](name="fk_sex")) 
    private Register sex; 

    @OneToOne(fetch=FetchType.EAGER) 
    @JoinColumn(name="emp_martial_status", nullable=false, [email protected](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$1$1.run(PersistenceUnitServiceImpl.java:172) 
     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) 
     at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667) 
     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.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$1$1.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 
+0

persistence.xmlを投稿できますか?データソースの定義ですか? – teacurran

+0

また、Base.javaのソースを投稿できますか? – teacurran

+0

私はスキーマである問題を発見しました。 –

答えて

0

Personクラスからschema = "medici"を削除した場合、コードは機能します(マイナスの多くのタイプミス)。

ここにスキーマを置くことは、実際にはベストプラクティスではありませんので、削除することをお勧めします。プロジェクトで複数のスキーマを使用する場合は、persistence.xmlに2つの異なる永続性単位を設定し、使用しているスキーマに応じて異なるエンティティ・マネージャを呼び出す方がよいでしょう。

+0

私はコードを英語にリファクタリングしてしまい、残念なことに私はおそらくいくつかのスポットを見逃してしまったためにタイプミスが発生しましたが、これが機能するかどうか試してみます。 –

関連する問題