Issue
I have a class User which is Entity. When I'm trying to map it in hibernate.cfg.xml
<mapping class="com.igorgorbunov3333.entities.User"/>
get an error:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.igorgorbunov3333.entities.User
But when I map class User programmatically It's work fine.
configuration.addAnnotatedClass(User.class);
What is the reason?
My Entity class:
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;
}
}
Solution
Try to use 4.3.6.Final version of hibernate. What hibernate version do you use? With 5.2.1.Final I saw the same problem. Solve by changing hibernate version.
Answer https://forum.hibernate.org/viewtopic.php?f=1&t=1043461&p=2489997&hilit=hibernate.cfg.xml#p2489997
Answered By - Andrey