Hi,
Is there a possibility to map a java.util.Map property containing REFERENCED
content (Map<String, SomeBeanStoredAsReferences>)
I am attempting to do so and I keep on running on problems.
I am working with the trunk of jackrabbit-ocm since I have seen support for
maps (ManageableMap & ManageableMapImpl). However, I do not find the
equivalent
of the BeanReferenceCollectionConverterImpl for maps
(BeanReferenceMapConverterImpl?).
In the example below: the map property is annotated with
@Collection(collectionConverter=BeanReferenceCollectionConverterImpl.class).
The BeanReferenceCollectionConverterImpl fails at restoring the Map content
because the ManageableObject associated to the Map property is not an
instance of ManageableCollection (it is in fact a ManageableMap).
My test is quite simple:
MODEL:
@Node(jcrMixinTypes = "mix:versionable")
public class Parent extends AbstractReferenceableEntity {
@Field(uuid = true, id = true)
private String id;
@Field(path = true)
private String path = defaultPath();
@Collection(collectionConverter =
BeanReferenceCollectionConverterImpl.class)
private Map<String, Child> childRefs = new HashMap<String, Child>();
getters and setters...
}
@Node(jcrMixinTypes = "mix:versionable")
public class Child extends AbstractReferenceableEntity {
@Field(path=true)
private String path = defaultPath();
@Field(uuid = true)
private String id;
getters and setters...
}
TEST:
@Test
public void persisting_and_restoring_child_references_in_map() {
Parent parent = new Parent();
parent.getChildRefs().put("c1", (Child)this.childDao.persist(new
Child()));
parent.getChildRefs().put("c2", (Child)this.childDao.persist(new
Child()));
parent.getChildRefs().put("c3", (Child)this.childDao.persist(new
Child()));
this.parentDao.persist(parent);
Parent reloaded = (Parent) this.parentDao.loadById(parent.getId());
assertThat(reloaded.getId(), is(notNullValue()));
assertThat(reloaded.getChildRefs(), is(notNullValue()));
assertThat(reloaded.getChildRefs().size(), is(equalTo(3)));
assertThat(reloaded.getChildRefs().get("c1"), is(notNullValue()));
assertThat(reloaded.getChildRefs().get("c2"), is(notNullValue()));
assertThat(reloaded.getChildRefs().get("c3"), is(notNullValue()));
}
I would really appreciate your help.
Also, if you know of a working alternative that would make my unit test
pass, I would be grateful.
Thanks in advance :)
Vincent Giguère