Objectify를 사용하여 Google App Engine 애플리케이션의 데이터 저장소에 액세스하고 있습니다. 내가 같은 것을 할 트랜잭션에서[GAE - Objectify] : LinkedHashMap이 키의 순서를 고려하지 않습니다.
@Entity
public class Client {
@Id String id;
}
@Entity
public class Queue {
@Index @Id String name;
@Load LinkedHashMap<String,Ref<Client>> clientsInQueue;
}
:
나는 2 엔티티가
Client newClient = new Client(...);
ofy().save().entity(newClient);
Queue selectedQueue = ofy().load().type(Queue.class).id(queueName).now();
selectedQueue.getClientsInQueue().put(newClient.getId(), Ref.create(newClient));
하지만 난이의 LinkedHashMap의 모든 요소를 인쇄 할 때, 나는 요소가 발견 정확히 의 역방향입니다. 내가 같이, 그것은을의 LinkedHashMap 2 클라이언트를 추가하고 저장하면 예를 들어
:
Queue selectedQueue = new LinkedHashMap<String,Ref<Client>>();
String id1 = "id1";
Client c1 = new Client(id1);
ofy().save().entity(c1);
String id2 = "id2"
Client c2 = new Client(id2);
ofy().save().entity(c2);
selectedQueue.getClientsInQueue().put(c1.getId(), Ref.create(c1));
selectedQueue.getClientsInQueue().put(c2.getId(), Ref.create(c2));
ofy().save().entity(selectedQueue);
Set<String> keys = selectedQueue.getClientsInQueue().keySet();
for(String key : keys){
Client c= selectedQueue.getClientsInQueue().get(key).get();
log.info("id: "+c.getId());
}
결과는 다음과 같습니다
ID : ID2
ID : ID1
왜 이런 행동을합니까? 나는 LinkedHashMap이 키의 순서를 유지해야한다는 것을 알고있다! LinkedHashMap을 GAE DataStore와 함께 사용하는데 문제가 있습니까?
미리 감사드립니다. 건배, 알레 산드로.
[LinkedHashMap] (http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html) 예측 가능한 반복 순서를 사용하여 맵 인터페이스의 해시 테이블 및 링크 된 목록 구현. 이 구현은 HashMap과 달리 모든 항목을 통해 실행되는 이중 연결 목록을 유지 관리합니다. 이 링크 된 목록은 일반적으로 키가 맵에 삽입 된 순서 (삽입 순서) 인 반복 순서를 정의합니다. – mancioshell