Suggested Pages

Tuesday, September 11, 2012

Cannot create TypedQuery for query with more than one return - Problem

In this post it's shown a common problem when using a typed query in JPA.

Problem


NamedQuery


@NamedQuery(name = "User.findUserByUsername", query = "SELECT u,p FROM User u JOIN u.profile p WHERE u.username=:username"),


Stacktrace

java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return
 at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:506)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)



Solution


Replace this:
 
   entityManager.createNamedQuery("User.findUserByUsername",User.class);

with

  entityManager.createNamedQuery("User.findUserByUsername");

No comments :

Post a Comment

Suggested Pages