无法获得org.hibernate.persister.entity.SingleTableEntityPersister的构造函数 [英] Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

查看:87
本文介绍了无法获得org.hibernate.persister.entity.SingleTableEntityPersister的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上是hibernate的新手,并试图设置2个类。帐户和人员。现在我所要做的就是使用注释创建一对一的双向依赖关系。以下是一些细节和代码片段:



以下是我添加到构建路径中的库,也许我错过了任何内容:



http://prntscr.com/1jbew4



帐户:

 包后端; 

import java.util.Random;
import java.util.Collection;
import java.util.TreeSet;
import javax.persistence。*;

@Entity
@Table(name =Account)
public class Account {

public static Random rnd = new Random();
private int id;
私人字符串用户名;
私人长密码;
私人长盐;
私人人物;
私人字符串角色;
私人收藏<帐户>好友列表;

公共账户(){

}

公共账户(字符串用户名,长密码,人员,字符串角色){
超();
this.username = username;
this.password =密码;
this.setSalt();
this.person = person;
this.role =角色;
this.friendlist = new TreeSet< Account>();

$ b $ @ $
@GeneratedValue
@Column(name =Id)
public int getId(){
return id ;
}

public void setId(int id){
this.id = id;


@Column(name =Username)
public String getUsername(){
return username;
}

public void setUsername(String username){
this.username = username;

$ b $ @Column(name =Password)
public long getPassword(){
return password;

$ b $ public void setPassword(String password){
this.password =(long)salt + password.hashCode();

$ b $ @Column(name =Salt)
public long getSalt(){
return salt;
}

public void setSalt(){
this.salt = rnd.nextLong();
if(this.salt <0){
this.salt = this.salt *(-1);



@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name =Person_FK)
public Person getPerson(){
return person;
}

public void setPerson(Person person){
this.person = person;

$ b @Column(name =Role)
public String getRole(){
return role;


public void setRole(String role){
}

Person:

 包后端; 

import javax.persistence。*;

@Entity
@Table(name =Person)
public class Person {

private int id;
private String firstName;
private String lastName;
私人字符串街道;
private int houseNumber;
private String tel;
私人字符串电子邮件;
私人字符串移动;
私人帐户帐户;
$ b $ public Person(){

}

public Person(int id,String firstName,String lastName,String street,
int houseNumber,String tel,String email,String mobile,
账户){
super();
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.street = street;
this.houseNumber = houseNumber;
this.tel = tel;
this.email =电子邮件;
this.mobile = mobile;
this.account = account;

$ b $ @ $
@GeneratedValue
@Column(name =Id)
public int getId(){
return id ;
}

public void setId(int id){
this.id = id;

$ b $ @Column(name =Firstname)
public String getFirstName(){
return firstName;
}

public void setFirstName(String firstName){
this.firstName = firstName;


$ b @Column(name =Lastname)
public String getLastName(){
return lastName;
}

public void setLastName(String lastName){
this.lastName = lastName;

$ b $ @Column(name =Street)
public String getStreet(){
return street;
}

public void setStreet(String street){
this.street = street;


@Column(name =Housenumber)
public int getHouseNumber(){
return houseNumber;
}

public void setHouseNumber(int houseNumber){
this.houseNumber = houseNumber;


@Column(name =Tel)
public String getTel(){
return tel;
}

public void setTel(String tel){
this.tel = tel;

$ b $ @Column(name =Email)
public String getEmail(){
return email;
}

public void setEmail(String email){
this.email = email;


@Column(name =Mobile)
public String getMobile(){
return mobile;
}

public void setMobile(String mobile){
this.mobile = mobile;
}

@OneToOne(mappedBy =person,cascade = CascadeType.ALL)
public Account getAccount(){
return account;
}

public void setAccount(Account account){
this.account = account;


Hibernate cfg xml:

 <?xml version ='1.0'encoding ='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0 .dtd>
< hibernate-configuration>
< session-factory>
<! - 备选1:MySQL - >

<! - 数据库连接设置:MySQL - >
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.url> jdbc:mysql:///chat.application.db< / property>
< property name =connection.username> root< / property>
< property name =connection.password>< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>


<! - JDBC连接池(使用内置) - >
< property name =connection.pool_size> 1< / property>


<! - 启用Hibernate的自动会话上下文管理 - >
< property name =current_session_context_class>线程< / property>

<! - 禁用二级缓存 - >
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>

<! - 将所有执行的SQL回复到stdout - >
< property name =show_sql> true< / property>
< property name =format_sql> true< / property>

<! - 在启动时删除并重新创建数据库模式 - >
< property name =hbm2ddl.auto>建立< / property>

< property name =hibernate.format_sql> true< / property>

<! - Auflistung der gemappten Klassen(Package + Class-Name) - >
< mapping class =backend.Account/>
< mapping class =backend.Person/>

<! - < mapping class =backend.Role/> - >
< / session-factory>
< / hibernate-configuration>

这是我的问题。当我尝试启动一个简单的主类来创建一些对象并保存它们时,我只是想测试一下:
$ b

(%%%%错误创建SessionFactory %%%% = printStackTrace之前的try-catch结果)

 信息:HHH000397:使用ASTQueryTranslatorFactory 
%%%%错误创建SessionFactory %%%%
org.hibernate.MappingException:无法获得org.hibernate.persister.entity.SingleTableEntityPersister $ b $的构造函数org.hibernate.persister.internal。 PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
。在org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)LT
。在org.hibernate.internal.SessionFactoryImpl&;初始化> (SessionFactoryImpl.java:385)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
在后端.Hib ernateSessionFactory.currentSession(HibernateSessionFactory.java:21)
at backend.HibernateSessionFactory.getCfg(HibernateSessionFactory.java:48)
at backend.Main.main(Main.java:14)
引起:org.hibernate.HibernateException:无法在org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer实例默认的tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
(EntityTuplizerFactory.java:138)
在org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)$ b $ LT b。在org.hibernate.tuple.entity.EntityMetamodel&; INIT>(EntityMetamodel.java:341)
。在。 org.hibernate.persister.entity.AbstractEntityPersister<初始化>(AbstractEntityPersister.java:507)在org.hibernate.persister.entity.SingleTableEntityPersister
将INIT>(SingleTableEntityPersister.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.Nat iveConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate。 persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
... 7 more
导致:java.lang.reflect.InvocationTargetException $ b $在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(未知来源)
在org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
... 16 more
导致:org.hibernate.PropertyNotFoundException:无法在类后台找到属性salt的setter.Account
在org.hibernate.pro perty.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
at org.hibernate.mapping.Property.getSetter(Property。的java:326)在org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444

。在org.hibernate.tuple.entity.AbstractEntityTuplizer< INIT>(AbstractEntityTuplizer.java。 :201)
在org.hibernate.tuple.entity.PojoEntityTuplizer。< init>(PojoEntityTuplizer.java:82)
... 21 more
线程mainjava中的异常。 lang.NullPointerException
处的backend.Main.main backend.HibernateSessionFactory.getCfg(HibernateSessionFactory.java:48)
backend.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:28)
(主。 java:14)

所以我真的不知道如何处理这个异常。我试图谷歌它等,但我发现是有些人在他们的代码中有拼写错误,这是它的原因。但不幸的是我没有在我的代码中有拼写。有人能帮我吗?如果需要,我也很乐意发布我的SessionFactoryCode或主类。由于我是hibernate的新手,所以我会采取一切建议=)



BTW:SQL DB通过XAMPP运行。



Thanks。

解决方案

您缺少 salt



请将setter添加为

> public void setSalt(long salt){
this.salt = salt;
}


I am actually new to hibernate and tried to set up 2 classes. Account and Person. Now all i try to do is create a one to one bidirectional dependency using annotations. Here are some details and code snippets:

Here are my libraries which i added to the build path, maybe i missed anything:

http://prntscr.com/1jbew4

Account:

package backend;

import java.util.Random;
import java.util.Collection;
import java.util.TreeSet;
import javax.persistence.*;

@Entity
@Table(name = "Account")
public class Account {

    public static Random rnd = new Random();
    private int id;
    private String username;
    private long password;
    private long salt;
    private Person person;
    private String role;
    private Collection<Account> friendlist;

    public Account() {

    }

    public Account(String username, long password, Person person, String role) {
        super();
        this.username = username;
        this.password = password;
        this.setSalt();
        this.person = person;
        this.role = role;
        this.friendlist = new TreeSet<Account>();
    }

    @Id
    @GeneratedValue
    @Column(name = "Id")
    public int getId() {
        return id;
    }

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

    @Column(name = "Username")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "Password")
    public long getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = (long) salt + password.hashCode();
    }

    @Column(name = "Salt")
    public long getSalt() {
        return salt;
    }

    public void setSalt() {
        this.salt = rnd.nextLong();
        if (this.salt < 0) {
            this.salt = this.salt * (-1);
        }
    }

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "Person_FK")
    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    @Column(name = "Role")
    public String getRole() {
        return role;
    }

    public void setRole(String role) {
}

Person:

package backend;

import javax.persistence.*;

@Entity
@Table(name ="Person")
public class Person {

    private int id;
    private String firstName;
    private String lastName;
    private String street;
    private int houseNumber;
    private String tel;
    private String email;
    private String mobile;
    private Account account;

    public Person() {

    }

    public Person(int id, String firstName, String lastName, String street,
            int houseNumber, String tel, String email, String mobile,
            Account account) {
        super();
        this.id= id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.street = street;
        this.houseNumber = houseNumber;
        this.tel = tel;
        this.email = email;
        this.mobile = mobile;
        this.account = account;
    }

    @Id
    @GeneratedValue
    @Column(name="Id")
    public int getId() {
        return id;
    }

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

    @Column(name="Firstname")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }


    @Column(name="Lastname")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name="Street")
    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Column(name="Housenumber")
    public int getHouseNumber() {
        return houseNumber;
    }

    public void setHouseNumber(int houseNumber) {
        this.houseNumber = houseNumber;
    }

    @Column(name="Tel")
    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @Column(name="Email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name="Mobile")
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @OneToOne(mappedBy = "person", cascade = CascadeType.ALL)   
    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }
}

Hibernate cfg xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Alternative 1: MySQL -->

        <!-- Database connection settings: MySQL -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql:///chat.application.db</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>


        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <property name="hibernate.format_sql">true</property>

        <!-- Auflistung der gemappten Klassen (Package + Class-Name) -->
        <mapping class="backend.Account"/>
        <mapping class="backend.Person"/>

        <!-- <mapping class="backend.Role"/> -->
    </session-factory>
</hibernate-configuration>

And here is my problem. when i try to start a simple main class creating some objects and saving them, just to test, i get this:

( %%%% Error Creating SessionFactory %%%% = result of my try-catch before printStackTrace)

INFO: HHH000397: Using ASTQueryTranslatorFactory
%%%% Error Creating SessionFactory %%%% 
org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at backend.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:21)
    at backend.HibernateSessionFactory.getCfg(HibernateSessionFactory.java:48)
    at backend.Main.main(Main.java:14)
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
    ... 7 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
    ... 16 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property salt in class backend.Account
    at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
    at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
    at org.hibernate.mapping.Property.getSetter(Property.java:326)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
    ... 21 more
Exception in thread "main" java.lang.NullPointerException
    at backend.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:28)
    at backend.HibernateSessionFactory.getCfg(HibernateSessionFactory.java:48)
    at backend.Main.main(Main.java:14)

So i really dont know how to handle this exception. I tried to google it and such but all i found out is that some people had spelling mistakes in their code and this was the reason for it. but unfortunately i dont have spellies in my code. Can someone help me? I will be happy to also post my SessionFactoryCode or the main class if neccessary. Due to the fact that i am new to hibernate i take every advise =)

BTW: SQL DB is running via XAMPP.

Thanks.

解决方案

You are missing setter for salt property as indicated by the exception

Please add the setter as

 public void setSalt(long salt) {
      this.salt=salt;
 }

这篇关于无法获得org.hibernate.persister.entity.SingleTableEntityPersister的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆