无法获取org.hibernate.persister.entity.UnionSubclassEntityPersister

时间:2017-02-02 19:05:38

标签: hibernate session jpa exception wildfly

任何人都可以帮我解决此异常吗?我尝试解决这个问题,但无法解决。它发生在我这之后:

 public Entidade() {
      FacesContext facesContext = FacesContext.getCurrentInstance();
      HttpSession session = (HttpSession)facesContext.getExternalContext().getSession(false);
      fazenda = (Fazenda) session.getAttribute("fazenda");
 }

然后出现了这个异常:

  

引起:org.hibernate.MappingException:无法获取org.hibernate.persister.entity.UnionSubclassEntityPersister的构造函数       在org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:401)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:852)[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]       ......还有13个       引起:org.hibernate.InstantiationException:无法实例化测试对象:br.com.teclogica.model.Especie       在org.hibernate.engine.internal.UnsavedValueFactory.instantiate(UnsavedValueFactory.java:60)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       at org.hibernate.engine.internal.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:85)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.tuple.PropertyFactory.buildIdentifierAttribute(PropertyFactory.java:87)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.tuple.entity.EntityMetamodel。(EntityMetamodel.java:163)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.persister.entity.AbstractEntityPersister。(AbstractEntityPersister.java:520)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       在org.hibernate.persister.entity.UnionSubclassEntityPersister。(UnionSubclassEntityPersister.java:93)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[rt.jar:1.8.0_112]       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)[rt.jar:1.8.0_112]       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[rt.jar:1.8.0_112]       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)[rt.jar:1.8.0_112]       在org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)[hibernate-core-4.3.7.Final.jar:4.3.7.Final]       ......还有17个

这是异常告诉我它无法实例化的类:

@Entity
public class Especie extends Entidade implements Serializable, BaseInterface {
    private static final long serialVersionUID = 3726838446858443624L;

    private String familia;
    private String descricao;

    public String getDescricao() {
         return descricao;
     }

    public void setDescricao(String descricao) {
         this.descricao = descricao;
    }

    public String getFamilia() {
         return familia;
    }

    public void setFamilia(String familia) {
         this.familia = familia;
    }
}

这是我更改了该代码块的父类:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@SequenceGenerator(name = "seq", sequenceName = "seq", allocationSize = 1)
public class Entidade implements Serializable, BaseInterface {

    private static final long serialVersionUID = -8347493862254802654L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "seq")
    protected long id;
    private boolean excluivel;
    protected String nome;
    @OneToOne
    private Fazenda fazenda;

    public Entidade() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
        fazenda = (Fazenda) session.getAttribute("fazenda");
    }

    public long getId() {
         return id;
    }

    public void setId(long id) {
         this.id = id;
    }

    public boolean isExcluivel() {
         return excluivel;
    }

    public void setExcluivel(boolean excluivel) {
         this.excluivel = excluivel;
    }

    public String getNome() {
         return nome;
    }

    public void setNome(String nome) {
         this.nome = nome;
    }

    @Override
    public String getKey() {
         return nome;
    }

    @Override
    public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result + (int) (id ^ (id >>> 32));
         return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
             return true;
        if (obj == null)
             return false;
        if (getClass() != obj.getClass())
            return false;
        Entidade other = (Entidade) obj;
        if (id != other.id)
            return false;
        return true;
    }

    public Fazenda getFazenda() {
         return fazenda;
    }

    public void setFazenda(Fazenda fazenda) {
         this.fazenda = fazenda;
    }

}

0 个答案:

没有答案