membersound
membersound

Reputation: 86935

"Named query not known" for named Hibernate query?

What might be the problem?

@Entity
@NamedQueries( {
    @NamedQuery(name = User.ALL,
                query = "SELECT u FROM User u")
})

public class User {
    public static final String ALL = "User.all";
}

public class Service {
    find... with ... User.ALL
}

Stacktrace:

Caused by: org.hibernate.MappingException: Named query not known: User.all
    at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:93)
    at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1407)
    at $Session_a5ad46cfa25.getNamedQuery(Unknown Source)
    at $Session_a5ad46cf913.getNamedQuery(Unknown Source)
    at de.medicshare.dal.HibernateCrudServiceDAO.findUniqueWithNamedQuery(HibernateCrudServiceDAO.java:83)
    at $CrudServiceDAO_a5ad46cfa19.findUniqueWithNamedQuery(Unknown Source)
    at $CrudServiceDAO_a5ad46cfa1b.findUniqueWithNamedQuery(Unknown Source)
    at $CrudServiceDAO_a5ad46cf931.findUniqueWithNamedQuery(Unknown Source)
    at de.medicshare.pages.Signup.proceedSignup(Signup.java:82)
    at de.medicshare.pages.Signup.dispatchComponentEvent(Signup.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:923)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1106)
    ... 90 more

Upvotes: 7

Views: 11255

Answers (2)

R...
R...

Reputation: 2630

I had similar issue when I renamed an Entity class in my package. Make sure the full class name for the persistence unit in the persistence.xml matches your Entity class. e.g.

   <persistence-unit name="your_PU_name" transaction-type="JTA">
      ...
      <class> [ make sure here is the FQN of your entity class ] </class>
      ...
   </persistence-unit>

Upvotes: 0

dann.dev
dann.dev

Reputation: 2494

Not sure if this will be your issue but check out this post here.

The issue was the use of:

org.hibernate.annotations.Entity

Instead of:

javax.persistence.Entity

Upvotes: 3

Related Questions