我正在使用Hibernate JPA(注释)和MySQL创建一个简单的应用程序。我不断得到一个:
WARN: HHH000183: no persistent classes found for query class: from
tn.ensi.cloudtrustproject.dao.entity.Country
测试Hibernate映射时。
到目前为止,我无法找到问题所在。请任何帮助。
这是我的hibernate.cfg.xml:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name=
"hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name=
"hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/TrustCloud</property>
<property name="hibernate.connection.pool_size">1</property>
<property name=
"hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider
</property>
<property name= "hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<mapping class="tn.ensi.cloudtrustproject.dao.entity.Country" ></mapping>
<mapping class="tn.ensi.cloudtrustproject.dao.entity.CloudUser"></mapping>
</session-factory>
</hibernate-configuration>
这是HibernateUtil:
public class HibernateUtil {
private static SessionFactory sessionFactory= buildSessionFactory();
private static ServiceRegistry serviceRegistry;
private static Session session=null;
private static SessionFactory buildSessionFactory(){
try{
Configuration configuration= new Configuration();
configuration.configure("config/hibernate.cfg.xml");
serviceRegistry=new
StandardServiceRegistryBuilder().
applySettings(configuration.getProperties()).build();
return configuration.buildSessionFactory (serviceRegistry);
}
catch (Throwable ex){
System.err.println("Failed to cerate SessionFactory object"+ ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
public static Session openSession(){
return sessionFactory.openSession();
}
public static Session getCurrentSession(){
return sessionFactory.getCurrentSession();
}
public static void close(){
sessionFactory.close();
}
}
Test.java类:
package tn.ensi.cloudtrustproject.util;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class Test {
static Session session= HibernateUtil.openSession();
public static void main(String[] args) {
session.createQuery("from tn.ensi.cloudtrustproject.dao.entity.Country
").list();
}
}
实体类: 的 的
的package tn.ensi.cloudtrustproject.dao.entity;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name="country")
public class Country implements Serializable{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
@Column(name="countryid")
private Integer countryId ;
@Column(name="countrydes")
private String countryDes;
public Country(Integer countryId, String countryDes) {
super();
this.countryId = countryId;
this.countryDes = countryDes;
}
public Country() {
super();
// TODO Auto-generated constructor stub
}
public Integer getCountryId() {
return countryId;
}
public void setCountryId(Integer countryId) {
this.countryId = countryId;
}
public String getCountryDes() {
return countryDes;
}
public void setCountryDes(String countryDes) {
this.countryDes = countryDes;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
return "Country [countryId=" + countryId + ", countryDes=" + countryDes
+ "]";
}
}
的
项目: project
创建表:
答案 0 :(得分:0)
您在config/hibernate.cfg.xml
中提到了配置文件。请检查它是否存在于同一位置。