문제

I have the following query that works under Hibernate but not under eclipse:

select o from Organisation o where o.code=:code and o.type=:type

It is not clear to me why this is the case, I was hoping someone else could elaborate for us. The error being returned is:

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].

We have made no other changes apart from switching the provider class in the persistence.xml file to indicate we are now using eclipselink.

도움이 되었습니까?

해결책

Looks like EclipseLink is not scanning the portion of your JAR files/classes that contain the Organisation class. Declare it explicitly in persistence.xml and see what happens:

<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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top