Map<String, Type> myMap = new HashMap<String, Type>();
Query query = session.createQuery("" +
"SELECT a " +
"FROM Articulo a ");
List<Object> list = query.list();
// Add all query elements to the hashmap
for (Object entrada : lista) {
myMap.put(entrada.getKey(), (Type) entrada);
// Type someOtherObject = entrada.getReferencedProperty();
}
Type someObject = (Type) myMap.get("someValidKey").getReferencedProperty(); //normal getter
這裏someObject
出來null
和對象被分離。但是,如果我取消註釋someOtherObject
行。關係被正確提取。休眠爲什麼我的對象變得分離?
這是怎麼回事?
這些實際上是在相同的方法嗎?這種區分非常重要。我猜不是,因爲'codLineas'沒有在您發佈的代碼中的任何地方定義。 – rmlan
@rmlan對不起,我正在簡化代碼,我錯過了。我現在編輯它。代碼是同一方法的一部分。 – harogaston