Question

please convert the sql in hql

SQL Statement : select username from useraccout where email = "parameter value"

More description:

while running the code i am getting this error:

public  List dispUser(String email){
    Query query = em.createQuery("SELECT u.username FROM Useraccout u WHERE u.email=:email)");
    query.setParameter(email, email);
    List search = query.getResultList();
    return search;
}

while running the code i am getting following error

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException:
Useraccout is not mapped [SELECT u.username FROM Useraccout u WHERE u.email=:email1)]
        at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:624)
        at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Was it helpful?

Solution

It appears you haven't mapped a class named Useraccount. My guess is that either:

  • You've mapped a class named Useraccount and have typed the name of this class incorrectly in the query
  • You haven't mapped any classes. This indicates that you don't understand the basics of Hibernate. In short, every class that maps to a database table needs to define this mapping using either an XML file or annotations.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top