<Classname> is not mapped [SELECT ...
klauskinski Dec 4, 2012 4:33 PMHi,
I'm trying to retrieve an "Users" object from my database querying by username/password.
I have the following Entity:
@Entity(name = "users")
public class User implements Serializable {
private static final long serialVersionUID = 7898904802394084838L;
@Id
private long userid;
private String name;
private String password;
@Column(name = "att_new", columnDefinition = "TINYINT(1)")
private boolean attNew;
@Column(name = "perm_login", columnDefinition = "TINYINT(1)")
private boolean permLogin;
@Column(name = "perm_admin", columnDefinition = "TINYINT(1)")
private boolean permAdmin;
I have the following Object trying to retrieve a User object:
@Stateless
public class UserBean implements UserIf {
@PersistenceContext(unitName = "JPADB")
private EntityManager entityManager;
public UserBean() { }
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
@Override
public User findUserByUsernamePassword(User user) {
String q = "SELECT p from User p WHERE p.name = :name AND p.password = SHA1(:pass)";
Query query = entityManager.createQuery(q);
// String q = "SELECT * from users as p WHERE p.name = ? AND p.password = SHA1(?)";
// Query query = entityManager.createNativeQuery(q,User.class);
query.setParameter( "name", user.getName() );
query.setParameter( "pass", user.getPassword() );
User u = (User) query.getSingleResult();
return u;
}
}
When I now call findUserByUsernamePassword from inside an EJB I'm getting:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [SELECT p from User p WHERE p.name = :name AND p.password = SHA1(:pass)]
What is causing the error here?
Remark: UserBean is not used as an EJB! It is instantiated in an EJB and called from there (after injecting entityManager).