3 Replies Latest reply on Feb 16, 2006 4:56 AM by epbernard

    Double Many to Many

    chrismalan

      This is a somewhat unusual scenario. There are persons both working for this concern and persons who are clients. They share the same database table. Then there are different groups of people. Among the staff they can be admin staff and social workers and what have you. Among the clients they can be any of a number of groups, pensioners, jobless people, substance abusers, etc.

      Any person can be a member of any number of groups. Then any number of staffmembers can be responsible for any number of groups.

      So, we have two m-m relationships:
      person -- group as a member
      person -- group as the owner of one or more groups

      One m-m relationship between two tables work fine, but when I define the second one (the two relationship tables have different names, of course) I get null pointer exceptions.

      impl19:34:24,082 INFO [Configuration] processing collection mappings
      19:34:24,131 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=nfss.par
      java.lang.NullPointerException
       at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:104)
       at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:877)
      ements Serializable


      After a long stack trace comes:
      implement at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)
      19:34:24,374 INFO [EJB3Deployer] Deployed: file:/usr/local/jboss-4.0.3/server/default/deploy/nfss.par
      19:34:24,376 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
      
      --- MBeans waiting for other MBeans ---
      ObjectName: jboss.j2ee:service=EJB3,module=nfss.par
       State: FAILED
       Reason: java.lang.NullPointerException
      
      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.j2ee:service=EJB3,module=nfss.par
       State: FAILED
       Reason: java.lang.NullPointerException
      s Serializable

      Removing one of the m-m relationships solves the problem. I tried it from both sides - the relationship tables defined in different classes for the two relationships and then defining the relationship tables in the same class for the two relationships. No go.

      Can this be done? It should be possible.

      I user jBoss 4.0.3 and jBossIDE-1.5 and JDK 1.5.0.01

      Thanks,

        • 1. Re: Double Many to Many
          epbernard

          you'll need to show the definitions of your manu to many

          • 2. Re: Double Many to Many
            chrismalan

            Hi Emmanuel,

            Thanks for your answer. This is how it looks:
            First, the Principal - Group m-m ralationship where the principal is a member of the group

            The Group persistence bean

            @ManyToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE},
             fetch = FetchType.EAGER)
             @JoinTable(
             table=@Table(name="PRINCIPAL_GROUP"),
             joinColumns={@JoinColumn(name="GROUP_ID")},
             inverseJoinColumns={@JoinColumn(name="PRINCIPAL_ID")}
             )
             public Set<Principal> getMembers() {
             return members;
             }


            Now the Principal persistence bean
            @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
             fetch = FetchType.EAGER,
             mappedBy="members")
             public Set<Group> getGroups() {
             return groups;
             }


            Now the Principal - Group m-m relationship where any number of principals own any number of groups

            This is the Principal persistence Bean
            @ManyToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE},
             fetch = FetchType.EAGER)
             @JoinTable(
             table=@Table(name="PRINCIPAL_OWNED"),
             joinColumns={@JoinColumn(name="PRINCIPAL_ID")},
             inverseJoinColumns={@JoinColumn(name="GROUP_ID")}
             )
             public Set<Group> getSerfs() {
             return serfs;
             }


            On the Group side

            @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
             fetch = FetchType.EAGER,
             mappedBy="serfs")
             public Set<Principal> getOwners() {
             return owners;
             }


            I've also tried to have both relationship table definitions in one persistence bean.



            • 3. Re: Double Many to Many
              epbernard

              Please provide a minimal test case and post it to JIRA
              http://opensource2.atlassian.com/projects/hibernate/secure/Dashboard.jspa