Java 冬眠不';我不想在hibernate.cfg.xml中映射该类
我有一个类用户,它是实体。当我试图在hibernate.cfg.xml中映射它时Java 冬眠不';我不想在hibernate.cfg.xml中映射该类,java,hibernate,persistence,Java,Hibernate,Persistence,我有一个类用户,它是实体。当我试图在hibernate.cfg.xml中映射它时 <mapping class="com.igorgorbunov3333.entities.User"/> 原因是什么 我的实体类: package com.igorgorbunov3333.entities; import javax.persistence.*; /** * Created by Игорь on 01.07.2016. */ @Entity @T
<mapping class="com.igorgorbunov3333.entities.User"/>
原因是什么
我的实体类:
package com.igorgorbunov3333.entities;
import javax.persistence.*;
/**
* Created by Игорь on 01.07.2016.
*/
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String email;
private String password;
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
您的hibernate配置文件(hibernate.cfg.xml)应该包含到实体类的映射。如下所示:
<mapping resource="com/igorgorbunov3333/entities/User.hbm.xml"/>
请检查一下。尝试使用hibernate的4.3.6.Final版本。您使用什么hibernate版本?在5.2.1.1决赛中,我看到了同样的问题。通过更改hibernate版本来解决此问题 答复
我犯了同样的错误,我做了与您相同的事情(直接映射类),它也起了作用。这对我来说没有任何意义,所以我查看了源代码并看到了这一点
/**
* Use the mappings and properties specified in the given application resource. The format of the resource is
* defined in <tt>hibernate-configuration-3.0.dtd</tt>.
*
* @param resource The resource to use
*
* @return this for method chaining
*
* @throws HibernateException Generally indicates we cannot find the named resource
*/
public Configuration configure(String resource) throws HibernateException {
standardServiceRegistryBuilder.configure( resource );
// todo : still need to have StandardServiceRegistryBuilder handle the "other cfg.xml" elements.
// currently it just reads the config properties
properties.putAll( standardServiceRegistryBuilder.getSettings() );
return this;
}
/**
*使用给定应用程序资源中指定的映射和属性。资源的格式是
*在hibernate-configuration-3.0.dtd中定义。
*
*@param resource要使用的资源
*
*@返回此链接以进行方法链接
*
*@throws-HibernateException通常表示找不到命名资源
*/
公共配置(字符串资源)引发HibernateException{
standardServiceRegistryBuilder.configure(资源);
//todo:仍然需要让StandardServiceRegistryBuilder处理“other cfg.xml”元素。
//目前它只读取配置属性
properties.putAll(standardServiceRegistryBuilder.getSettings());
归还这个;
}
因此,基本上,目前并不是hibernate.cfg.xml文件中的所有项都被读取,而且我无法找出hibernate API提供的任何替代项。首先,请确保正确打印了包名,然后发布实体类too@AndrewToblilko,假设您指的是orh.hibernate.*和javax.persistence.*之间的冲突。我使用了javax.persistence.entity谢谢你的回复!
/**
* Use the mappings and properties specified in the given application resource. The format of the resource is
* defined in <tt>hibernate-configuration-3.0.dtd</tt>.
*
* @param resource The resource to use
*
* @return this for method chaining
*
* @throws HibernateException Generally indicates we cannot find the named resource
*/
public Configuration configure(String resource) throws HibernateException {
standardServiceRegistryBuilder.configure( resource );
// todo : still need to have StandardServiceRegistryBuilder handle the "other cfg.xml" elements.
// currently it just reads the config properties
properties.putAll( standardServiceRegistryBuilder.getSettings() );
return this;
}