Hi Emmanuel,
Thanks for your pointer. I have looked at the example in AddressBook, and directoryEntries does indeed appear to map the relationship in the same way we are aiming to achieve. However I note that the AddressBook.getDirectoryEntries() method is never called by the org.hibernate.test.annotations.indexcoll.IndexedCollectionTest , at least in the current revisions that I am able to browse via
http://anonsvn.jboss.org/, and my summary attempts to get this working in my own code have continued to fail.
In my case (continuing my previous example), the first call to the containsKey method in my following example returns true...
Code:
class EntityA {
@OneToMany
@MapKey(name="entityB">
Map<EntityB, EntityC> entityCs = new HashMap<EntityB, EntityC>();
boolean containsKey(EntityB entityB) {
return entityCs.containsKey(entityB1);
}
}
However, calling it a second time with a different instance of entityB which exists in a valid relationship causes it to return false, when it really should return true.
It appears that the first call to a method on the Map (in my example, Map.containsKey() ) triggers a db query, and the return value indicates that the Map does indeed contain the key. However the second call to Map.containsKey() for another valid key in a valid relationship returns false.
If I use a list instead, and do a list traversal, everything works fine...
Code:
class EntityA {
@OneToMany
List<EntityC> entityCs = new ArrayList<EntityC>();
boolean containsKey(EntityB entityB) {
for(EntityC entityC : entityCs) {
if (entityC.getEntityB().equals(entityB)) {
return true;
}
}
return false;
}
}