3 Replies Latest reply on Aug 26, 2005 5:42 AM by jc7442

    Entity bean association ???

    jc7442

      Hi,

      I have the folowing entity bean:

      @Entity()
      public class NodeBO implements Persistent {
       ...
       private NodeBO parent;
       @ManyToOne
       public NodeBO getParent() {
       return parent;
       }
      
       public void setParent(NodeBO parent) {
       this.parent = parent;
       }
      }
      


      First I do not write ManyToOne annotations. I create 2 instances :n1 and :n2, :n1 has no parent and :n2 has :n1 has parent. I retrieve :n2 by a query, if I invoke getParent method on :n2, it returns :n2.

      I just add the annotaions and with the same code now it works fine.

      I do not understand the differences between my 2 codes. Any explanations are welcome.

      When there is no annotations, having a look to DB, parent field is mapped using a tiny blob. It should correspond to a default annotation what's the default annotation ?

      Explanations or reference in the documentation on how to manage bean association are welcome !!!

      J-C




        • 1. Re: Entity bean association ???
          epbernard

          I don't know what you're talking about.
          An association has to have an annotation describing it's logical multiplicity

          • 2. Re: Entity bean association ???
            jc7442

            If I do not specify any association, entity bean are deployed, I can create instance in the DB and when I look the DB using an SQL browser (I have a mySql db), I can see a column with the name of my field containing a tiny blob.
            If I add the ManyToOne annotation, using the same browser I see that the mapping for my object has changed and now instead of a tiny blob, I see the PK of the objects.
            My question was just to understand why with no annotation I have a tiny blob (is it a default value or something that may be paramater ?).

            Another problem I try to solve is:
            - I have a node entity bean that handles an interface leaf. In JDO2, this kind of mapping is possible, I just need to specify the list of valid classes that implment this interface (if classes are not specified, all classes are valid). I try to do the same with hibernate, I do not find annotation to specify the list of valid classes. If I just add ManyToOne annotation, I have the following exception at deployment time:

            16:48:41,536 WARN [ServiceController] Problem creating service jboss.j2ee:module=Persistence.par,uid=20796783,service=EJB3
            org.hibernate.AnnotationException: Unable to find entity fr.biomerieux.dnachip.bo.classification.Leaf
             at org.hibernate.cfg.AnnotationBinder.bindFkSecondPass(AnnotationBinder.java:1480)
             at org.hibernate.cfg.FkSecondPass.secondPass(FkSecondPass.java:37)
             at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:31)
             at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:215)
             at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:876)
             at org.hibernate.ejb.HibernatePersistence.handleListenerCallbacks(HibernatePersistence.java:448)
             at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:438)
             at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:272)
             at org.jboss.ejb3.Ejb3Deployment.initializeManagedEntityManagerFactory(Ejb3Deployment.java:476)
             at org.jboss.ejb3.Ejb3Deployment.create(Ejb3Deployment.java:219)
             at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:34)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:252)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:234)
             at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
             at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:974)
             at $Proxy0.create(Unknown Source)
             at org.jboss.system.ServiceController.create(ServiceController.java:356)
             at org.jboss.system.ServiceController.create(ServiceController.java:295)
             at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
             at $Proxy17.create(Unknown Source)
             at org.jboss.ejb3.EJB3Deployer.create(EJB3Deployer.java:178)
             at org.jboss.deployment.MainDeployer.create(MainDeployer.java:919)
             at org.jboss.deployment.MainDeployer.create(MainDeployer.java:909)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:773)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:737)
             at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
             at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
             at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
             at $Proxy9.deploy(Unknown Source)


            I probably just missed something in the mapping, but I can not find what !!!



            • 3. Re: Entity bean association ???
              jc7442

              A thread that answer my interface problem:
              http://forum.hibernate.org/viewtopic.php?p=2238824#2238824