2014-09-30 4 views
0

독립 실행 형 JPA 도구 인 maven 프로젝트가 있습니다.JPA2 엔티티를 자동 검색 할 수 없습니다.

이 주요 프로젝트는 모든 엔티티 클래스를 포함하는 다른 프로젝트에 의존합니다.

그러나 JPA는 내 항목을 자동으로 찾지 않습니다. My Eclipse 프로젝트> properties> jpa> 자동 발견도 가능합니다.

내 persistence.xml을 : 그것은 대상/클래스/META-INF에 위치

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 

    <persistence-unit name="myapp-ds" transaction-type="RESOURCE_LOCAL">   
     <description>Vecchio</description> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <exclude-unlisted-classes>false</exclude-unlisted-classes> 
     <properties> 
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myapp" /> 
      <property name="javax.persistence.jdbc.user" value="root" /> 
      <property name="javax.persistence.jdbc.password" value="xxx" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
      <property name="hibernate.show_sql" value="true" />    
      <property name="hibernate.archive.autodetection" value="class"/> 
     </properties> 

    </persistence-unit> 

</persistence> 

.

오류, 엔티티를 사용하는 경우 것은 :

Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: model.legacy.dto.myentity 
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1184) 
    at it.test.Main.main(Main.java:23) 

답변

1

당신이 주요 항아리에 포함 된 유일한 클래스는 자동으로 지속성 단위로 검색됩니다, 독립 프로젝트를 사용하는 경우. 다른 jar는 전쟁에서 일어나는 것과 같은 아카이브에 포함되지 않지만 필요에 따라 classpath에서 검색됩니다. => 다른 프로젝트에서 생성 된 jar를 포함하는 엔티티 클래스는 기본적으로 스캔되지 않습니다.

<jar-file>full jar location</jar-file>을 사용할 수 있지만 모든 jar 파일을 동일한 디렉토리에 패키지하지 않으면 매우 이식성이 떨어지지 만 그 경우에도 설치 규칙 만 적용됩니다. 그래서 Hibernate Entity Manager 가이드와 같은 많은 문서가 JSE 환경에서 현재 jar의 외부에있는 모든 엔티티 클래스를 명시 적으로 나열하도록 권장하는 이유이다.

0

당신은 here를 읽어보십시오. 자동 작동하지 않는 감지하면 그렇지 않으면, 당신은 persistence.xml에 수동으로 개체를 삽입 할 수 있습니다

<persistence-unit ...> 
     <class>...</class> 
    </persistence> 
+1

모든 수업을 나열하고 싶지는 않습니다. 수업은 400+ –

관련 문제