JPA mapping: “QuerySyntaxException: foobar is not mapped…”

前端 未结 4 1532
青春惊慌失措
青春惊慌失措 2020-12-04 11:02

I\'ve been playing around with a very simple JPA example and am trying to tweak it to an existing database. But I can\'t get past this error. (Below.) It just has to be s

相关标签:
4条回答
  • 2020-12-04 11:31

    There is also another possible source of this error. In some J2EE / web containers (in my experience under Jboss 7.x and Tomcat 7.x) You have to add each class You want to use as a hibernate Entity into the file persistence.xml as

    <class>com.yourCompanyName.WhateverEntityClass</class>

    In case of jboss this concerns every entity class (local - i.e. within the project You are developing or in a library). In case of Tomcat 7.x this concerns only entity classes within libraries.

    0 讨论(0)
  • 2020-12-04 11:36

    JPQL mostly is case-insensitive. One of the things that is case-sensitive is Java entity names. Change your query to:

    "SELECT r FROM FooBar r"
    
    0 讨论(0)
  • 2020-12-04 11:45

    You have declared your Class as:

    @Table( name = "foobar" )
    public class FooBar {
    

    You need to write the Class Name for the search.
    from FooBar

    0 讨论(0)
  • 2020-12-04 11:53

    I got the same error while using other one entity, He was annotating the class wrongly by using the table name inside the @Entity annotation without using the @Table annotation

    The correct format should be

    @Entity //default name similar to class name 'FooBar' OR @Entity( name = "foobar" ) for differnt entity name
    @Table( name = "foobar" ) // Table name 
    public class FooBar{
    
    0 讨论(0)
提交回复
热议问题