tags:

views:

89

answers:

1

please convert the sql in hql

SQL Statement : s*elect 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)
+1  A: 

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.
Don