1 2 Previous Next 17 Replies Latest reply on Jan 29, 2002 4:07 PM by michele

    Does many to many relationship work in Jboss3.0 ?

    nick

      If anyone has successfully used a many-to-many relationship in Jboss 3.0 alpha (cmp2.0) then I will go away and make mine work. Mine works ok until I redeploy or restart jboss. My test client works fine then stops working after a Jboss restart.

        • 1. Re: Does many to many relationship work in Jboss3.0 ?
          jcarroll

          I have sucessfully created many-to-many relationships in 3.0. They are being updated via stateless session beans which are called both from standalone java clients (JUnit) and jsps/servlets. I'm using a nightly snapshot of JBoss from 1/9/2002.

          • 2. Re: Does many to many relationship work in Jboss3.0 ?
            michele

            How to download your snapshot version?

            Thanks
            Michele

            • 3. Re: Does many to many relationship work in Jboss3.0 ?

              I'm successful with one to one, many to one, many to many on JBoss 3.0 on the posted download. Followed the CMP2.0 docs carefully.

              • 4. Re: Does many to many relationship work in Jboss3.0 ?
                michele

                Do you use CMP 2.0 with JBoss 3.0alpha?
                Do you try the J2EE Tutorial AppRoster example by Sun
                on JBoss?
                Unfortunately I don't have an international credit card,
                so I can't read the CMP2.0 docs :-(

                I don't understand why the relationship setting works
                if the database table are empty when I first deploy
                my application and don't work the second time when
                database table aren't empty.

                Bye
                Michele

                • 5. Re: Does many to many relationship work in Jboss3.0 ?
                  nick

                  Hi Michele.

                  We seem to have the same problem. I am using Oracle.
                  The problem occurs only on an "add" to the relationship.
                  A "delete" always works fine.

                  I wonder if the above cases were tested after a re-deploy?

                  How does one get an updated Jboss3.0 copy ?

                  The Exception is thrown from org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.addRelation(JDBCCMRFieldBridge.java:582)

                  jdbc.bridge.JDBCCMRFieldBridge.createRelationLinks(JDBCCMRFieldBridge.java:465)

                  jdbc.bridge.RelationSet.add(RelationSet.java:82)


                  I would like to look at this source code.
                  How do you get access to it ?

                  Thanks, Nick.

                  • 6. Re: Does many to many relationship work in Jboss3.0 ?
                    michele

                    Hi Nick,
                    You can download an updated JBoss3.0 copy from
                    http://www.sourceforge.org with a tool named cvs,
                    you could use this two command from linux shell or windows command line:

                    cvs -d:pserver:anonymous@cvs.jboss.sourceforge.net:/cvsroot/jboss login

                    cvs -z3 -d:pserver:anonymous@cvs.jboss.sourceforge.net:/cvsroot/jboss co -D "2002-01-19" jboss-all

                    the option -D "2002-01-19" let you to download a version from 19nd january, not all version of jboss works.
                    The two command above let you to download the jboss3.0 source code ready to compile.

                    Don't you think it is strange that only you and me have this problem? Do you read the CMP2.0 doc? Perhaps there is a way to set a relationship different from Sun example.

                    Bye
                    Michele

                    • 7. Re: Does many to many relationship work in Jboss3.0 ?
                      michele

                      the forum app transform the command in a imoticons :-(
                      the right option is:

                      -d: pserver:anonymous@cvs.jboss.sourceforge.net:/cvsroot/jboss

                      without space or carriage return

                      • 8. Re: Does many to many relationship work in Jboss3.0 ?
                        jcarroll

                        I don't have the CMP2 docs and haven't tried the sun examples. I just read the O'Reilly EJB book and the EJB 2.0 spec and followed those. Also I'm using mySQL instead of Oracle, but it works fine after a redeploy. Like I mentioned I've only tried later version of JBoss from CVS so maybe there was a problem in an earlier version. I currently have an app that uses many-to-many, one-to-many, and one-to-one bidirectional relationships and all of them work fine.

                        • 9. Re: Does many to many relationship work in Jboss3.0 ?
                          michele

                          I try latest version of JBoss from CVS now but my source don't work :-(
                          Could you send me a working example of many to many relationship between entity bean?
                          Or if you want I send you a simple example of non working relationship.

                          Bye
                          Michele

                          my e-mail is
                          fabbrimichele@libero.it

                          • 10. Re: Does many to many relationship work in Jboss3.0 ?

                            If you don't have CMP 2.0 docs, there are numerous examples in the forums.

                            Start simple. Use the simplest many to many case you can find, with each EJB having a simple (e.g. String) primary key.

                            Make sure you look at the JDBC logs to ensure that all queries and updates that you would expect are there and completed successfully. If necessary, run the SQL from a separate client to convince yourself what you see is what should happen.

                            One of the key differences between many to many and many to one is that when you don the ejb field-db field mapping in jboss.xml, in many to many you are mapping for the side of the role you're on, whereas in many to one, on the "Many" side you are mapping the ejb field for the side of the role you're on to the db field for the "One" side. Don't know if this helps but if you get it wrong depending on your field names you may not notice a problem even though it doesn't work.

                            Don't populate relationships in ejbCreate. This is a common problem for people who don't read the specs. Populate relationships in ejbPostCreate. Also, make sure when adding removing to a collection, say one called "lines", you add or remove from the collection, not replace the entire collection. e.g. getLines().add(theLine), unless that's what you want to do. If you replace the collection (such as setLines(newLines)), you loose all the relationships for that collection.

                            I routinely run JBoss in -classic mode and things have become very stable.

                            • 11. Re: Does many to many relationship work in Jboss3.0 ?
                              lepekhine

                              I use standard distributed package of JBoss 3.0alpha. I've deployed Sun "cmpcustomer" example into it. This example is distributed with Sun j2sdkee1.3. In the example we have many-to many and one-to-many relationships. I can tell you, that many-to-many relationship does work, but one-to-many does not, at least as they were written by Sun. The course was in the manner of adding childs to the customer bean. If you try to add address to customer from post-create method in address bean - it doesn't work. If you create new address in customer bean and then add it to the customer address children - it works. So I suppose, that some problems with relationships may be concerned with your buisiness logic, the manner of adding children and so on. As for me I decided to avoid calling another EJB methods from the post-create method. Happy for me my buisiness logic allow it. Try to remove post-create methods body and I am sure everything will work fine. After that you can find what line of code was the course of the error.

                              • 12. Re: Does many to many relationship work in Jboss3.0 ?
                                chris70

                                Guys,
                                What about the performance of one-to-many and many-to-many? How many records you have in DB while testing these relationships?

                                Thanks,
                                Chris.

                                • 13. Re: Does many to many relationship work in Jboss3.0 ?
                                  michele

                                  Hi,

                                  I read all yours advice but I don't understand why my app
                                  don't work :-(
                                  I don't set any relationship in ejb-create, I have also try a simple app adapted from testsuit, but if I create entity beans then I stop JBoss3.0, I restart JBoss3.0 and I try to set a relationship with previous entity the server report these errors:

                                  java.rmi.ServerException: null
                                  Embedded Exception
                                  A CMR field cannot be set or added to a relationship in ejbCreate; this should be done in the ejbPostCreate method instead.;

                                  at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:634)

                                  at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)

                                  at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:142)

                                  at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)

                                  at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)

                                  at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)

                                  at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)

                                  at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:289)

                                  at org.jboss.ejb.Container.invoke(Container.java:609)
                                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
                                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                                  at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:320)
                                  at java.lang.reflect.Method.invoke(Native Method)
                                  at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
                                  at sun.rmi.transport.Transport$1.run(Unknown Source)
                                  at java.security.AccessController.doPrivileged(Native Method)
                                  at sun.rmi.transport.Transport.serviceCall(Unknown Source)
                                  at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
                                  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
                                  at java.lang.Thread.run(Unknown Source)

                                  • 14. Re: Does many to many relationship work in Jboss3.0 ?
                                    michele

                                    this is my beans:

                                    -------------------------------------------------------
                                    ejb-jar.xml:
                                    -------------------------------------------------------
                                    <?xml version="1.0"?>
                                    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">

                                    <ejb-jar>
                                    <enterprise-beans>

                                    <ejb-name>ControllerEJB</ejb-name>
                                    org.jboss.test.cmp2.relationship.manyToManyBidirectional.ControllerHome
                                    org.jboss.test.cmp2.relationship.manyToManyBidirectional.Controller
                                    <ejb-class>org.jboss.test.cmp2.relationship.manyToManyBidirectional.ControllerBean</ejb-class>
                                    <session-type>Stateless</session-type>
                                    <transaction-type>Container</transaction-type>


                                    A - many-to-many bidirectional
                                    <ejb-name>A_ManyToMany_Bi_EJB</ejb-name>
                                    <local-home>org.jboss.test.cmp2.relationship.manyToManyBidirectional.AHome</local-home>
                                    org.jboss.test.cmp2.relationship.manyToManyBidirectional.A
                                    <ejb-class>org.jboss.test.cmp2.relationship.manyToManyBidirectional.ABean</ejb-class>
                                    <persistence-type>Container</persistence-type>
                                    <prim-key-class>java.lang.Integer</prim-key-class>
                                    False
                                    <cmp-version>2.x</cmp-version>
                                    <abstract-schema-name>AManyToManyBi</abstract-schema-name>
                                    <cmp-field><field-name>id</field-name></cmp-field>
                                    <primkey-field>id</primkey-field>


                                    B - many-to-many bidirectional
                                    <ejb-name>B_ManyToMany_Bi_EJB</ejb-name>
                                    <local-home>org.jboss.test.cmp2.relationship.manyToManyBidirectional.BHome</local-home>
                                    org.jboss.test.cmp2.relationship.manyToManyBidirectional.B
                                    <ejb-class>org.jboss.test.cmp2.relationship.manyToManyBidirectional.BBean</ejb-class>
                                    <persistence-type>Container</persistence-type>
                                    <prim-key-class>java.lang.Integer</prim-key-class>
                                    False
                                    <cmp-version>2.x</cmp-version>
                                    <abstract-schema-name>BManyToManyBi</abstract-schema-name>
                                    <cmp-field><field-name>id</field-name></cmp-field>
                                    <primkey-field>id</primkey-field>

                                    </enterprise-beans>


                                    <ejb-relation>
                                    <ejb-relation-name>AB_ManyToMany_Bi</ejb-relation-name>
                                    <ejb-relationship-role>
                                    <ejb-relationship-role-name>A-has-Bs</ejb-relationship-role-name>
                                    Many
                                    <relationship-role-source>
                                    <ejb-name>A_ManyToMany_Bi_EJB</ejb-name>
                                    </relationship-role-source>
                                    <cmr-field>
                                    <cmr-field-name>b</cmr-field-name>
                                    <cmr-field-type>java.util.Collection</cmr-field-type>
                                    </cmr-field>
                                    </ejb-relationship-role>
                                    <ejb-relationship-role>
                                    <ejb-relationship-role-name>B-has-As</ejb-relationship-role-name>
                                    Many
                                    <relationship-role-source>
                                    <ejb-name>B_ManyToMany_Bi_EJB</ejb-name>
                                    </relationship-role-source>
                                    <cmr-field>
                                    <cmr-field-name>a</cmr-field-name>
                                    <cmr-field-type>java.util.Collection</cmr-field-type>
                                    </cmr-field>
                                    </ejb-relationship-role>
                                    </ejb-relation>

                                    </ejb-jar>

                                    -------------------------------------------------------
                                    jboss.xml
                                    -------------------------------------------------------
                                    <?xml version="1.0" encoding="Cp1252"?>


                                    <enterprise-beans>


                                    <ejb-name>ControllerEJB</ejb-name>
                                    <jndi-name>ejb/Controller</jndi-name>


                                    <ejb-name>A_ManyToMany_Bi_EJB</ejb-name>
                                    <local-jndi-name>relation/manyToMany/bidirectional/A</local-jndi-name>


                                    <ejb-name>B_ManyToMany_Bi_EJB</ejb-name>
                                    <local-jndi-name>relation/manyToMany/bidirectional/B</local-jndi-name>

                                    </enterprise-beans>


                                    -------------------------------------------------------
                                    jbosscmp-jdbc.xml
                                    -------------------------------------------------------
                                    ?xml version="1.0" encoding="UTF-8"?>

                                    <!DOCTYPE jbosscmp-jdbc PUBLIC
                                    "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
                                    "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

                                    <jbosscmp-jdbc>


                                    <create-table>true</create-table>
                                    <remove-table>false</remove-table>
                                    <pk-constraint>true</pk-constraint>
                                    <read-ahead>on-find</read-ahead>



                                    <ejb-relation>
                                    <ejb-relation-name>AB_ManyToMany_Bi</ejb-relation-name>
                                    <table-mapping>
                                    <table-name>AB_ManyToManyBi</table-name>
                                    </table-mapping>
                                    </ejb-relation>


                                    </jbosscmp-jdbc>

                                    1 2 Previous Next