문제

내 태그 엔터티에 열쇠 세트가 포함 된 코스 엔티티가 있습니다. 특정 태그가있는 코스 목록을 얻기 위해 쿼리를 만드는 방법은 무엇입니까? 예를 들어, Java 태그가 지정된 모든 과정을 찾고 싶습니다.

내 엔티티는 다음과 같습니다.

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
 public class Course{

 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key key;

 @Persistent private Set<Key>       tags;
 //etc
 }

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Tag{

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent private String tagText;
}
도움이 되었습니까?

해결책

Tag tag = getTagFromString("java");
Key tagKey = tag.getKey();  // i will assume you have a getKey() method

PersistenceManger pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(Course.class);
q.setFilter("tags == :tagParam");

List<Course> coursesTaggedWithJava = (List<Course>) q.execute(tagKey);

다른 팁

나는 이것이 가능하지 않다고 생각합니다. Google DataStore는 조인 쿼리를 사용할 수 없습니다. 그러나 나는 착각 할 수있다.

여기 그리고 여기 GQL에 대한 자세한 정보를 찾을 수있는 웹 사이트입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top