i have a problem using hibernate with my java project and i hope that you can help me:
First, here is some of my code:
The Entity class
package de.zaed.entities;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="USER")
public class User {
/**
* the user id in the database
*/
@Id
private Long id;
/**
* the username of a user
*/
private String username;
/**
* the users password
*/
private String password;
/**
* The role of a user
*/
@OneToOne(mappedBy="user", cascade=CascadeType.ALL)
private UserRole role;
public Long getId() {
return id;
}
public String getPassword() {
return password;
}
public UserRole getRole() {
return role;
}
public String getUsername() {
return username;
}
public void setId(Long id) {
this.id = id;
}
public void setPassword(String password) {
this.password = password;
}
public void setRole(UserRole role) {
this.role = role;
}
public void setUsername(String username) {
this.username = username;
}
}
the part where i add the class to the AnnotationConfiguration
config.addAnnotatedClass(User.class);
config.addAnnotatedClass(UserRole.class);
config.configure("hibernate.cfg.xml");
now my problem:
while executing the following code:
User dbUser = new User();
dbUser.setUsername(username);
dbUser.setPassword(password);
Session session = DatabaseService.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(dbUser);
session.flush();
session.close();
I get the
org.hibernate.MappingException: Unknown entity: de.zaed.entities.User
error while session.save(dbUser) is called.
I've read many posts in forums and some tutorials but i could not find a fix for my problem. Hope you can help me.
Thanks, kaQn4p