我有以下查询在Hibernate下运行但不在eclipse下运行:
select o from Organisation o where o.code=:code and o.type=:type
我不清楚为什么会这样,我希望其他人可以为我们详细说明。返回的错误是:
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Error compiling the query [select o from Organisation o where o.code=:code and o.type=:type]. Unknown entity type [Organisation].
除了在persistence.xml文件中切换提供程序类以指示我们现在正在使用eclipselink之外,我们没有做任何其他更改。
答案 0 :(得分:1)
看起来EclipseLink没有扫描包含Organization类的JAR文件/类的部分。在persistence.xml中明确声明它,看看会发生什么:
<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="YourPersUnit">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>foo.bar.Organisation</class>
</persistence-unit>
</persistence>