2017-05-12 10 views
0

クエリクラスが見つかりません永続クラスは得続ける: WARN: HHH000183: no persistent classes found for query class: from tn.ensi.cloudtrustproject.dao.entity.CountryテストHibernateマッピング:私はHibernateはJPA(注釈)とMySQL.Iを使用して簡単なアプリケーションを作成してい

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

テーブルが作成されます。

Table country

+0

エンティティクラスは切り詰められています。エンティティのテーブルマッピングはどこで定義しますか? – StanislavL

+0

試すsession.createQuery( "国から ")。リスト();フルパスを設定する代わりに – kimy82

+0

@StanislavL hibernate.cfg.xmlでマッピングを定義しました。エンティティクラスcoomplete – ManelPhD

答えて

0

あなたが言及している設定ファイルはconfig/hibernate.cfg.xmlに存在します。同じ場所に存在するかどうかを確認してください。

+0

はい。こちらをご覧ください:https://i.stack.imgur.com/dCboI.png – ManelPhD

関連する問題