未映射Enity

我正在尝试使用hibernate创建一个小项目,但我得到了错误“类型未映射[从类型o中选择o]”,我在hibernate.cfg.xml中添加了映射但仍然出错。

Type.java:

package com.formation.gestionprojet.doa.entity; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="Type") public class Type implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id private Long id; private String name; private String description; private String active; public Type() { super(); // TODO Auto-generated constructor stub } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getActive() { return active; } public void setActive(String active) { this.active = active; } } 

hibernate.org.xml:

      com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/gestion_projet?createDatabaseIfNotExist=true root root  org.hibernate.dialect.MySQLDialect  org.hibernate.cache.NoCacheProvider  true  update     

hibernateUtil.java:

 package com.formation.gestionprojet.utils; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; @SuppressWarnings("deprecation") public class HibernateUtil { private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; static { try { Configuration configuration = new Configuration(); configuration.configure("config/hibernate.cfg.xml"); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (HibernateException ex) { System.err.println("Error creating Session: " + 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(){ if(sessionFactory!=null){ sessionFactory.close(); } } } 

Test.Java

 package com.formation.gestionprojet.utils; import org.hibernate.Session; public class Test { static Session session = HibernateUtil.openSession(); public static void main(String[] args) { session.createQuery("select o from Type o").list(); } } 

解决了 ! 问题是我使用的hibernate版本所以我改变它,HibernateUtil的变化。