0 Replies Latest reply on Sep 15, 2005 5:58 AM by pascal jeannenot

    Composite Pattern & EJB3 mapping problem

    pascal jeannenot Newbie

      Hello,

      I've tried to implement composite pattern with EJB3, but it seems impossible.

      This is my code :

      1- parent class

      @Entity
       @Table(name = "groupesetediteurs")
       @Inheritance(strategy = InheritanceType.JOINED)
       public abstract class EGroupesEtEditeurs
       implements Serializable {
       protected boolean isroot = false;
       private String nom = null;
      
      
       private List<EGroupesEtEditeurs> groupesEtEditeurs = new ArrayList<EGroupesEtEditeurs>();
      
       private int id;
      
       @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
      
      
       public void setId(int id) {
       this.id = id;
       }
      
      
       public void add(EGroupesEtEditeurs ge) {
       this.groupesEtEditeurs.add(ge);
       }
      
       public void del(EGroupesEtEditeurs ge) throws Exception {
       this.groupesEtEditeurs.remove(ge);
       }
      
       public void setNom(String nom){
       this.nom = nom;
       }
      
       private void setRoot(boolean isroot) {
       this.isroot = isroot;
       }
      
      
       public String getNom() {
       return nom;
       }
      
       
       @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
       @JoinTable(
       table=@Table(name="GroupesEditeurs"),
       joinColumns = { @JoinColumn( name="parent_id") },
       inverseJoinColumns = @JoinColumn( name="enfant_id")
       )
       public List<EGroupesEtEditeurs> getGroupesEtEditeurs(){
       return groupesEtEditeurs;
       }
      
      
      
       private void setGroupesEtEditeurs(List<EGroupesEtEditeurs> groupesEtEditeurs) {
       this.groupesEtEditeurs = groupesEtEditeurs;
       }
      
      
       public boolean isRoot() {
       return isroot;
       }
      
      }
      



      2- node class
      @Entity
      @Table(name = "groupedepresse")
      public class EGroupeDePresse extends EGroupesEtEditeurs {
      
       public EGroupeDePresse() {}
      
      
       public EGroupeDePresse(String nom) throws Exception {
       this.setNom(nom);
       }
      
      
       public void add(EGroupesEtEditeurs ge) throws Exception {
       super.add(ge);
       }
      
       public void del(EGroupesEtEditeurs ge) throws Exception {
       super.del(ge);
       }
      
       public void setNom(String nom){
       super.setNom(nom);
       }
      
      
      
       public String getNom() {
       return super.getNom();
       }
      
       
       public List<EGroupesEtEditeurs> getGroupesEtEditeurs(){
       return super.getGroupesEtEditeurs();
       }
      
       public void makeRoot(){
       this.isroot = true;
       }
      
       public boolean isRoot() {
       return super.isroot;
       }
      
      
      }
      



      3- Leaf class

      @Entity
      @Table(name = "editeur")
      public class EEditeur extends EGroupesEtEditeurs implements Serializable{
      
       private List<ETitre> titres = new ArrayList<ETitre>();
       private ArrayList interlocuteurs = new ArrayList();
      
       public EEditeur() {}
      
      
       public EEditeur(String nom) throws Exception {
       this.setNom(nom);
       }
      
      
       public void add(EGroupesEtEditeurs ge) throws Exception {
       throw new Exception(
       "Un Editeur ne peut pas posséder de Groupes ou d'Editeurs");
       }
      
      
       public void del(EGroupesEtEditeurs ge) throws Exception {
       throw new Exception(
       "Un Editeur ne peut pas posséder de Groupes ou d'Editeurs");
       }
      
      
       public String getNom() {
       return super.getNom();
       }
      
      
       public void setNom(String nom){
       super.setNom(nom);
       }
      
      
       public List<EGroupesEtEditeurs> getGroupesEtEditeurs(){
       return super.getGroupesEtEditeurs();
       }
      
       public boolean isRoot() {
       return false;
       }
      
       @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
       @JoinTable(
       table=@Table(name="EditeurTitres"),
       joinColumns = { @JoinColumn( name="editeur_id") },
       inverseJoinColumns = @JoinColumn( name="titre_id")
       )
       public List<ETitre> getTitres() {
       return titres;
       }
      
      
       public void setTitres(List<ETitre> titres) {
       this.titres = titres;
       }
      
       public void addTitre(ETitre titre) {
       //ETitre.validation(titre);
       this.titres.add(titre);
       }
      
       public void delTitre(ETitre titre) {
       this.titres.remove(titre);
       }
      
      
      }
      
      



      4- and the error trace

      WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=entites-produits.par
      
      org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(groupesEtEditeurs)]
      
       at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:265)
       at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:252)
       at org.hibernate.mapping.Property.isValid(Property.java:175)
       at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:330)
       at org.hibernate.mapping.JoinedSubclass.validate(JoinedSubclass.java:38)
       at org.hibernate.cfg.Configuration.validate(Configuration.java:815)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:976)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:178)
       at org.jboss.ejb3.entity.EntityManagerFactoryLoader.loadFactory(EntityManagerFactoryLoader.java:44)
       at org.jboss.ejb3.entity.EntityManagerFactoryLoader.loadFactory(EntityManagerFactoryLoader.java:31)
       at org.jboss.ejb3.Ejb3Module.initializeManagedEntityManagerFactory(Ejb3Module.java:290)
       at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:141)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:233)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:215)
       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.system.ServiceController$ServiceProxy.invoke(ServiceController.java:950)
       at $Proxy0.create(Unknown Source)
       at org.jboss.system.ServiceController.create(ServiceController.java:342)
       at org.jboss.system.ServiceController.create(ServiceController.java:281)
       at sun.reflect.GeneratedMethodAccessor6.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 $Proxy10.create(Unknown Source)
       at org.jboss.ejb3.EJB3Deployer.create(EJB3Deployer.java:157)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       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.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:80)
       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 $Proxy11.create(Unknown Source)
       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.GeneratedMethodAccessor8.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 $Proxy6.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:501)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:277)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:267)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:217)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       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:950)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:436)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       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 $Proxy4.start(Unknown Source)
       at org.jboss.deployment.SARDeployer.start(SARDeployer.java:273)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:973)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:774)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:737)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:721)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       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 $Proxy5.deploy(Unknown Source)
       at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:434)
       at org.jboss.system.server.ServerImpl.start(ServerImpl.java:315)
       at org.jboss.Main.boot(Main.java:195)
       at org.jboss.Main$1.run(Main.java:463)
      
      



      Thank you for your help !