jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christophe Lombart" <christophe.lomb...@gmail.com>
Subject Re: OCM Bean referencing Interface
Date Mon, 01 Dec 2008 13:02:00 GMT
Hi Antoine,

I have the same error here. it is a bug. Unfortunately, it seems that typed
collections based on interface doesn't work well.

There is a workaround. in the class EntityA, use the following setting for
the list :

      @Collection(elementClassName=MyInterface.class)
       List<MyInterface> entityB;

elementClassName is used only for untyped collections but you can use it for
typed collections.  I will create a patch to avoid this redundant setting
and add a new unit test.

FYI, you have to add also the annotation @Node on the interface otherwise it
will be ignored by the OCM.

Thanks,
Christophe



On Mon, Dec 1, 2008 at 12:21, alarcher <antoinelarcher@gmail.com> wrote:

>
> Hello,
>
> I encountered an anormal behaviour while using interfaces in my OCM beans.
> It works when using @Bean but it throws an exception using @Collection.
>
> Here is the test case :
>
> [Case 1 : Working Great]
>
> - Let's define two classes and one interface
>
> @Node
> public class EntityA {
>        @Field(path=true) String path;
>        @Bean MyInterface entityB;
>
>        public String getPath() {
>                return path;
>        }
>        public void setPath(String path) {
>                this.path = path;
>        }
>        public MyInterface getEntityB() {
>                return entityB;
>        }
>        public void setEntityB(MyInterface entityB) {
>                this.entityB = entityB;
>        }
> }
>
> public interface MyInterface {
>        public String getId();
> }
>
> @Node
> public class EntityB implements MyInterface {
>        @Field private String name;
>        @Field private String id;
>
>        public String getId() {
>                return id;
>        }
>
>        public void setId(String id) {
>                this.id = id;
>        }
>
>        public String getName() {
>                return name;
>        }
>
>        public void setName(String name) {
>                this.name = name;
>        }
> }
>
>
> - Let's store an instance of EntityA containing an instance of EntityB
>
> List<Class> classes = new ArrayList<Class>();
> classes.add(EntityA.class);
> classes.add(EntityB.class);
>
> Mapper mapper = new AnnotationMapperImpl(classes);
> ObjectContentManager ocm =  new ObjectContentManagerImpl(session, mapper);
>
> EntityA a = new EntityA();
> a.setPath("/ocm_" + System.currentTimeMillis());
>
> EntityB b = new EntityB();
> b.setId("ID_B");
> b.setName("NAME_B");
>
> a.setEntityB(b);
>
> ocm.insert(a);
> ocm.save();
>
>
> - OCM marshalls EntityA and EntityB correctly so that the repository looks
> like this :
>
> /ocm_1228129394656
> /ocm_1228129394656/[jcr:primaryType = nt:unstructured]
> /ocm_1228129394656/[ocm_classname = com.heavenize.test.interfaces.EntityA]
> /ocm_1228129394656/entityB
> /ocm_1228129394656/entityB/[name = NAME_B]
> /ocm_1228129394656/entityB/[id = ID_B]
> /ocm_1228129394656/entityB/[jcr:primaryType = nt:unstructured]
> /ocm_1228129394656/entityB/[ocm_classname =
> com.heavenize.test.interfaces.EntityB]
>
>
>
>
> [Case 2 : Not Working]
>
>
> - Let's change EntityA so that it contains a list of MyInterface
>
> @Node
> public class EntityA {
>        @Field(path=true) String path;
>        @Collection List<MyInterface> MyInterface entityB;
>
>        public String getPath() {
>                return path;
>        }
>        public void setPath(String path) {
>                this.path = path;
>        }
>        public List<MyInterface> getEntityB() {
>                return entityB;
>        }
>        public void setEntityB(List<MyInterface> entityB) {
>                this.entityB = entityB;
>        }
> }
>
>
> - Let's store an instance of EntityA containing a list of one EntityB
> instance
>
> List<Class> classes = new ArrayList<Class>();
> classes.add(EntityA.class);
> classes.add(EntityB.class);
>
> Mapper mapper = new AnnotationMapperImpl(classes);
> ObjectContentManager ocm =  new ObjectContentManagerImpl(session, mapper);
>
> EntityA a = new EntityA();
> a.setPath("/ocm_" + System.currentTimeMillis());
>
> List<MyInterface> bList = new ArrayList<MyInterface>();
> EntityB b = new EntityB();
> b.setId("ID_B");
> b.setName("NAME_B");
> bList.add(b);
>
> a.setEntityB(bList);
>
> ocm.insert(a);
> ocm.save();
>
>
> - An exception is thrown :
>
> org.apache.jackrabbit.ocm.exception.JcrMappingException: Cannot load class
> interface com.heavenize.test.interfaces.MyInterface; nested exception is
> java.lang.ClassNotFoundException: interface
> com.heavenize.test.interfaces.MyInterface
> java.lang.ClassNotFoundException: interface
> com.heavenize.test.interfaces.MyInterface
>
>
>
>
> Do you think I am wrong while setting the list of MyInterface, or this is
> clearly a bug of the OCM layer while setting a list of "interfaces" objects
> ?
>
>
> Thanks a lot,
> Antoine Larcher
> --
> View this message in context:
> http://www.nabble.com/OCM-Bean-referencing-Interface-tp20770134p20770134.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message