Java 我得到一个org.hibernate.hql.internal.ast.QuerySyntaxException:未映射异常
我正在尝试从我的表中获取所有对象,但我不明白为什么会出现此错误…:org.hibernate.hql.internal.ast.QuerySyntaxException:未映射calamartest.personne 我可以毫无问题地插入,但查询不起作用 我的代码:Java 我得到一个org.hibernate.hql.internal.ast.QuerySyntaxException:未映射异常,java,hibernate,Java,Hibernate,我正在尝试从我的表中获取所有对象,但我不明白为什么会出现此错误…:org.hibernate.hql.internal.ast.QuerySyntaxException:未映射calamartest.personne 我可以毫无问题地插入,但查询不起作用 我的代码: List<Personne> listPersonne; EntityManagerFactory entityManagerFactory = Persistence.createEntityMana
List<Personne> listPersonne;
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("testhibernate0");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
listPersonne = entityManager.createQuery("from calamartest.personne", Personne.class).getResultList();
entityManager.getTransaction().commit();
entityManager.close();
不要叫我的类名:
listPersonne = entityManager.createQuery("from Personne", Personne.class).getResultList();
错误来自您的查询:
来自calamartest.personne
。没有类personne
,但存在personne
还有一件事,确保实体在正确的包中。在代码中,您向calamartest.Personne发出请求,而在
持久化.xml
中,类Personne
位于bean
包下。他认为JPQL使用了calamartest.Personne
之类的表名!成功了!我在想,我必须执行一种SQL请求,所以“calamartest”用于postgres模式。但它指的是我的类,所以正如你所说的,我将“{myschema}.{mytab}”替换为{myClass},它成功了:)天哪。非常感谢。我只是在这上面浪费了两个小时。。。我早就知道了!谢谢你的提醒。类名,而不是表名。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="testhibernate0" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>bean.Personne</class>
<class>bean.Maison</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.id.new_generator_mappings" value="false"/>
[...]
</properties>
</persistence-unit>
</persistence>
listPersonne = entityManager.createQuery("from calamartest.personne", Personne.class).getResultList();
listPersonne = entityManager.createQuery("from Personne", Personne.class).getResultList();