Hibernate HHH000183:没有为查询类找到持久化类

时间:2017-02-05 22:53:22

标签: java spring hibernate

我有一个关于我的hibernate映射的问题,我正在使用Spring和hibernate创建一个项目,我面临一个问题,到目前为止我可以解决它,到目前为止我找不到能够帮助我的人,所以我映射数据库并按预期完成所有操作,但我收到此消息:

HHH000183:找不到查询类的持久化类:FROM com.inbox.model.Estado

我的hibernate.cfg.xml就像这样

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
	<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
	<property name="hibernate.connection.url">jdbc:mysql://inboxmysqldb.c4lcntgo83fr.us-west-2.rds.amazonaws.com</property>
	<property name="hibernate.connection.username">inboxuser</property>
	<property name="hibernate.connection.password">xxxxxx</property>


	<!-- <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> -->
	<property name="hibernate.show_sql">false</property>
	<!-- <property name="hibernate.hbm2ddl.auto">true</property>-->
	<property name="hibernate.connection.pool_size">10</property>
	
	<property name="hibernate.current_session_context_class">thread</property>
	<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
	<!-- Mapping files -->
	<!-- <mapping class="com.inbox.model.Box"/> -->
	<mapping class="com.inbox.model.Estado"/>
</session-factory>
</hibernate-configuration>

我的课程映射如下:

package com.inbox.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;


@Entity(name="com.inbox.model.Estado")
@Table(name = "estado", 
uniqueConstraints={@UniqueConstraint(columnNames={"id"})})
public class Estado implements IdentifierInterface, Serializable{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3625863483844458267L;

	@Id
	@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
	
	@Column(name="id", nullable=false, unique=true, length=11)
	private Integer id;
	
	@Column(name="nome", length=20, nullable=true)
	private String nome;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}	
	
}

的HibernateUtil:

public class HibernateUtil {
	private static SessionFactory sessionFactory = buildSessionFactory();    
    private static SessionFactory buildSessionFactory() {
		if (sessionFactory == null) {
			Configuration configuration = new Configuration();
			configuration.configure("hibernate.cfg.xml");
			ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
					.applySettings(configuration.getProperties()).build();
			sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		}
		return sessionFactory;
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }   
    
	public static Session getSession() {
		return getSessionFactory().openSession();
	}
}

根据要求,按照查询

	public T findById(int id) {
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		try {
			Query byIdQuery = session.createQuery("FROM " + entityClassName + " as c WHERE c.id = :id");
			byIdQuery.setParameter("id", id);
			return (T) byIdQuery.uniqueResult();
		} catch (Exception e) {
			throw new InboxException(e);
		} finally {
			session.close();
		}
	}

我没有想法尝试修复。

提前致谢

0 个答案:

没有答案