7

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
5
  • why didn't you use just name="User.all"? Commented Apr 21, 2012 at 19:06
  • Eclipse can only confirm usage of constants. So, if I create the query with "User.all" it is a string that does not get checked. Using User.ALL gets checked before compiling if I spell it wrong. Commented Apr 21, 2012 at 19:48
  • 1
    Can you post your hibernate.cfg.xml/persistence.xml? Commented May 25, 2012 at 14:26
  • Turn on your "hibernate.log" and check if appears a string like "[org.hibernate.cfg.annotations.QueryBinder] (main:) Binding Named query: User.all => SELECT u FROM User u"... Then check your persistence file and check if the class User is mapped. Commented Jun 21, 2012 at 20:49
  • Does this answer your question? Named query not known - Annotations & Hibernate Commented Feb 27, 2020 at 22:09

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

That's a good point to notice, but I used the proper import in mace case, unfortunately.
Ahh well worth a try. Have you declared the class in your hibernate.cfg.xml (extensions at end can vary) as a <mapping>?
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.