복붙노트

[SPRING] JPA 2.0에서 엔티티 자동 검색 방법

SPRING

JPA 2.0에서 엔티티 자동 검색 방법

나는 과거에 JPA 2.0에서 @Entity로 주석 처리 된 bean의 자동 감지 기능을 사용 하였지만 어떻게 찾을 수 없는지 확신합니다. persistence.xml의 클래스 XML 요소에 각 빈을 나열하는 대신 어떻게합니까?

해결법

  1. ==============================

    1.Spring 3.1부터 persistence.xml을 모두 잊어 버리고 다음과 같이 packagesToScan 속성을 사용하여 EntityManagerFactory를 구성 할 수도있다.

    Spring 3.1부터 persistence.xml을 모두 잊어 버리고 다음과 같이 packagesToScan 속성을 사용하여 EntityManagerFactory를 구성 할 수도있다.

    <bean id="entityManagerFactory" 
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:dataSource-ref="dataSource"
          p:packagesToScan="${jpa.entity.packages}">
    
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                  p:showSql="${hibernate.show_sql}"/>
        </property>
    
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            </props>
        </property>
    </bean>
    
  2. ==============================

    2.persistence.xml에 다음 줄을 추가해야합니다.

    persistence.xml에 다음 줄을 추가해야합니다.

    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    

    e.

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" ...>
        <persistence-unit name="YourPU" ...>
            <exclude-unlisted-classes>false</exclude-unlisted-classes>
            <properties>
                <property name="eclipselink.logging.level" value="ALL"/>
                <property name="eclipselink.ddl-generation" 
                    value="drop-and-create-tables"/>
            </properties>
        </persistence-unit>
    </persistence>
    
  3. ==============================

    3.Pascal Thivent의 대답을 참조하십시오 : persistence.xml에 요소가 필요합니까?

    Pascal Thivent의 대답을 참조하십시오 : persistence.xml에 요소가 필요합니까?

    다른 방법이 있지만 JPA 자체는 자동 스캔을 지원하지 않습니다. 엔티티를 참조하는 가장 간단하고 깨끗한 방법은 모델을 jar 파일로 패키지하고 MyModel.jar

  4. from https://stackoverflow.com/questions/16088112/how-to-auto-detect-entities-in-jpa-2-0 by cc-by-sa and MIT license