English 中文(简体)
JPA绘图:“QuerySyntaxException: foobar is notmapped.”
原标题:JPA mapping: "QuerySyntaxException: foobar is not mapped..."

我在玩弄一个非常简单的例子,试图把它拖到一个现有的数据库。 但是,我可以 error开这一错误。 (见下文) 这只是我看不到的一件简单的事情。

org.hibernate.hql.internal.ast.QuerySyntaxException: FooBar is not mapped [SELECT r FROM FooBar r]
  org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
  org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
  org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)

在以下文件管理类别(我的目标在于此)有两个方面:

  1. insert a row
  2. return all rows

插入完全是好的。 问题在于检索。 我尝试了<代码>的所有价值。 Query q = 实体Manager.create Query下参数,但无uck;我尝试以各种方式更重复说明这一类别(如一栏)。

请让我自封。 我确信,这是很小的。 我对日本人民军的不耐烦态度使我无法再行。

www.un.org/Depts/DGACM/index_spanish.htm 页: 1

@Entity
@Table( name = "foobar" )
public class FooBar {
    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="id")
    private int id;

    @Column(name="rcpt_who")
    private String rcpt_who;

    @Column(name="rcpt_what")
    private String rcpt_what;

    @Column(name="rcpt_where")
    private String rcpt_where;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getRcpt_who() {
        return rcpt_who;
    }
    public void setRcpt_who(String rcpt_who) {
        this.rcpt_who = rcpt_who;
    }

    //snip...the other getters/setters are here
}

www.un.org/Depts/DGACM/index_spanish.htm 页: 1

public class DocumentManager extends HttpServlet {
    private EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "ch.geekomatic.jpa" );

    protected void tearDown() throws Exception {
        entityManagerFactory.close();
    }

   @Override
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
       FooBar document = new FooBar();
       document.setRcpt_what("my what");
       document.setRcpt_who("my who");

       persist(document);

       retrieveAll(response);
   }

   public void persist(FooBar document) {
       EntityManager entityManager = entityManagerFactory.createEntityManager();
       entityManager.getTransaction().begin();
       entityManager.persist( document );
       entityManager.getTransaction().commit();
       entityManager.close();
   }

    public void retrieveAll(HttpServletResponse response) throws IOException {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();

        //  *** PROBLEM LINE ***
        Query q = entityManager.createQuery( "SELECT r FROM foobar r", FooBar.class );
        List<FooBar> result = q.getResultList();

        for ( FooBar doc : result ) {
            response.getOutputStream().write(event.toString().getBytes());
            System.out.println( "Document " + doc.getId()  );
        }
        entityManager.getTransaction().commit();
        entityManager.close();
    }
}

www.un.org/Depts/DGACM/index_spanish.htm The{tomcat-home}/webapps/ROOT/WEB-INF/classes/METE-INF/persistance.xml file

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

<persistence-unit name="ch.geekomatic.jpa">
    <description>test stuff for dc</description>

    <class>ch.geekomatic.jpa.FooBar</class>

    <properties>
        <property name="javax.persistence.jdbc.driver"   value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url"      value="jdbc:mysql://svr:3306/test" />
        <property name="javax.persistence.jdbc.user"     value="wafflesAreYummie" />
        <property name="javax.persistence.jdbc.password" value="poniesRock" />

        <property name="hibernate.show_sql"     value="true" />
        <property name="hibernate.hbm2ddl.auto" value="create" />
    </properties>

</persistence-unit>
</persistence>

www.un.org/Depts/DGACM/index_spanish.htm MySQL表说明:

mysql> describe foobar;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| rcpt_what  | varchar(255) | YES  |     | NULL    |                |
| rcpt_where | varchar(255) | YES  |     | NULL    |                |
| rcpt_who   | varchar(255) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
最佳回答

JPQL主要是对个案不敏感。 对案件敏感的事项之一是 Java实体名称。 回答:

"SELECT r FROM FooBar r"
问题回答

还有一个可能的错误来源。 In some J2EE / web Campbell/strong> (根据在Jbos7.x和Tomcat 7x下的经验) 各位必须增加每一类 你们希望把自己作为解放实体纳入文件persistence.xml

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

如果是小船,则涉及每个实体类别(当地,即项目内,你正在开发或图书馆)。 就Tomcat 7.x而言,这只涉及图书馆内的实体班。

你已宣布 班级:

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

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

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

正确格式应当

@Entity //default name similar to class name  FooBar  OR @Entity( name = "foobar" ) for differnt entity name
@Table( name = "foobar" ) // Table name 
public class FooBar{

与你的问题无关,但一旦我收到日本邮局地图,“QuerySyntaxException: foobar没有被描绘成......问题,因为我补充说:

@Entity(name="foo")
class Foobar{
...
}

and tried to refer Foobar

也可以是通知提供者,对于他们使用jakarta.persistence.*而不是javax的更新的秘密。 持久性。 * E/CN.6/2009/1。

HOPE IT DOESN T TAKE HOURS OF HEAD WALLING TO FIGURE THAT OUT





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...