2016-12-15 4 views
0

@Load를 사용하는 데 문제가 있습니다. Ref <> 기본적으로로드 그룹과 함께 @Load 주석을 테스트하기 위해 Objectify 웹 사이트의 사본 붙여 넣기를 만들었습니다.Objective Ref <>가 @Load와 함께 작동하지 않습니다.(). 그룹()

@Entity 
public static class Thing { 
    public static class Partial {} 
    public static class Everything extends Partial {} 
    public static class Stopper {} 

    @Id Long id; 
    @Load(Partial.class) Ref<Other> withPartial; 
    @Load(Everything.class) Ref<Other> withEveryhthing; 
    @Load(unless=Stopper.class) Ref<Other> unlessStopper; 

    public Ref<Other> getWithPartial() { 
     return withPartial; 
    } 

    public void setWithPartial(Ref<Other> withPartial) { 
     this.withPartial = withPartial; 
    } 

    public Ref<Other> getWithEveryhthing() { 
     return withEveryhthing; 
    } 

    public void setWithEveryhthing(Ref<Other> withEveryhthing) { 
     this.withEveryhthing = withEveryhthing; 
    } 

    public Ref<Other> getUnlessStopper() { 
     return unlessStopper; 
    } 

    public void setUnlessStopper(Ref<Other> unlessStopper) { 
     this.unlessStopper = unlessStopper; 
    } 
} 

다음 코드를 작성했습니다.

Other other = new Other(); 

Key<Other> otherKey = ofy().save().entity(other).now(); 

Thing thing = new Thing(); 
thing.setWithPartial(Ref.create(otherKey)); 

Key<Thing> thingKey = ofy().save().entity(thing).now(); 

Thing t = ofy().load().key(thingKey).now(); 

System.out.println("Is loaded: " + t.getWithPartial().isLoaded()); 

(). 다른 엔티티가 여전히 세션에로드됩니다. 그러나 문서화에는로드 될 그룹 클래스가 필요합니다.

답변

0

isLoaded() 메서드는 엔티티가 세션 캐시에 있는지 여부를 테스트합니다. 엔티티가 save() 일 뿐이므로 이미 세션 캐시에 있습니다.

로드 그룹의 동작을 테스트하려면 캐시를 ofy().clear()해야합니다.