2011-08-25 4 views
0

Hibernate가 엔티티에서 프로퍼티를 지연로드하도록 할 수 있습니까? 기본적으로로드되는 상속 된 프로젝트에는 몇 개의 clob이 있습니다. 주석을 주석으로 변환하기 전에 XML을 stop-gap으로 수정하고 싶습니다.Hibernate Lazy Load 프로퍼티 XML 매핑

답변

0

최대 절전 모드 5, this can be done as follows:. 당신은 단순히 @Basic(fetch = FetchType.LAZY)하여 개체 속성을 주석을 달 수 있습니다, 그리고

<plugin> 
    <groupId>org.hibernate.orm.tooling</groupId> 
    <artifactId>hibernate-enhance-maven-plugin</artifactId> 
    <version>${hibernate.version}</version> 
    <executions> 
     <execution> 
      <configuration> 
       <enableLazyInitialization>true</enableLazyInitialization> 
      </configuration> 
      <goals> 
       <goal>enhance</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

:

첫째, 당신은 다음과 같은 Maven 플러그인을 추가 할 필요가

:

@Entity(name = "Event") 
@Table(name = "event") 
public class Event extends BaseEntity { 

    @Type(type = "jsonb") 
    @Column(columnDefinition = "jsonb") 
    @Basic(fetch = FetchType.LAZY) 
    private Location location; 

    public Location getLocation() { 
     return location; 
    } 

    public void setLocation(Location location) { 
     this.location = location; 
    } 
} 

당신이 개체를 가져올 때

Event event = entityManager.find(Event.class, 
    eventHolder.get().getId()); 

LOGGER.debug("Fetched event"); 
assertEquals("Cluj-Napoca", event.getLocation().getCity()); 

Hibernate는 초를 사용하여 lazy 속성을로드 할 것이다 이전 선택 :

SELECT e.id AS id1_0_0_ 
FROM event e 
WHERE e.id = 1 

-- Fetched event 

SELECT e.location AS location2_0_ 
FROM event e 
WHERE e.id = 1 
관련 문제