그래서 순차적 인 일대 다 관계로 정렬 된 목록에있는 자식을 유지하려고합니다. 그들은 이미 "색인"속성을 가지고 있기 때문에 나는 http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html에 대한 조언을 따르고 "list-ordering"확장을 사용하여 index-property를 사용하여 자동 생성 된 순서 대신 자식의 순서를 결정합니다.DataNucleus의 목록 순서 확장을 사용하면 빈 목록이됩니다.
주석을 추가하자마자 아이들을 돌려 보내지 않고 빈 목록 만 제공합니다.
나는이 간단한 예제와 문제를 다시 :@PersistenceCapable(detachable = "true")
@FetchGroup(name = "parent.children", members = {@Persistent(name = "children")})
public class Parent {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
@Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="index ASC"))
private List<Child> children;
// getters/setters
}
@PersistenceCapable(detachable = "true")
public class Child {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private Integer index;
// getters/setters
}
DAO :
public void save(T entity) {
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(entity);
tx.commit();
} finally {
if(tx.isActive())
tx.rollback();
pm.close();
}
}
public T get(Key key, String... fetchGroups) {
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
addFetchGroups(pm, fetchGroups);
try {
tx.begin();
pm.setDetachAllOnCommit(true);
T entity = (T) pm.getObjectById(entityClass, key);
tx.commit();
return entity;
} finally {
if(tx.isActive())
tx.rollback();
pm.close();
}
}
테스트 코드 : 내가 잘못하고 오전 특히 아무것도
Parent parent = new Parent();
Child child = new Child();
child.setIndex(10);
parent.getChildren().add(child);
mParentDao.save(parent);
Parent parent2 = mParentDao.get(parent.getKey(), "parent.children");
있습니까?
[EDIT가 여기서 관련 로그 출력 :
데이터 저장소 : 키 부모 (ID없는 미)
데이터 저장소와 종류 부모 엔티티 퍼팅 : 키 부모 종류 아이 퍼팅 엔티티 (3)/어린이 (노 아이디 없습니다 아직)
데이터 저장소 : INDEX : 10
데이터 저장소 : 커밋 된 데이터 저장소 트랜잭션 : 0
데이터 저장소 : 시작 새 데이터 저장소 트랜잭션 : 1
데이터 저장소 : 키 부모와 종류 부모의 실체를 얻기 (3)
Datastore.Retrieve : 준비 중 부모 CHILD
Datastore.Retrieve의 모든 자식을 쿼리하려면 : 추가 정렬 : 인덱스 ASCENDING
Datastore.Retrieve : 쿼리 결과가 0입니다.
데이터 저장소 : 최선을 다하고 데이터 저장소 트랜잭션
나를 위해 작동합니다. GAE 플러그인 v2를 사용하고 있습니다. 로그를 사용하여 디버깅하고, GAE 데이터 저장소에 넣고 가져옵니다. – DataNucleus
일부 로그 출력을 추가했습니다. 기본적으로 엔티티가 올바르게 추가되고 데이터 저장소에 표시되지만, 어린이를 쿼리 할 때 어떤 이유로 0 개의 결과가 수신됩니다. –
나는 당분간 당황한 비슷한 문제를 안고있었습니다. 순서가 지정된 목록은주의해서 사용해야하며, 특히 커밋 전에 순서 필드를 변경하는 경우에는주의해야합니다. 해결 방법 : 주문 태그를 제거하고 목록에 COMPARATOR를 구현하십시오. – marcolopes