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.
How to download your snapshot version?
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.
Do you use CMP 2.0 with JBoss 3.0alpha?
Do you try the J2EE Tutorial AppRoster example by Sun
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.
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)
I would like to look at this source code.
How do you get access to it ?
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:email@example.com:/cvsroot/jboss login
cvs -z3 -d:pserver:firstname.lastname@example.org:/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.
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.
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.
my e-mail is
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.
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.
What about the performance of one-to-many and many-to-many? How many records you have in DB while testing these relationships?
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:
A CMR field cannot be set or added to a relationship in ejbCreate; this should be done in the ejbPostCreate method instead.;
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)
this is my beans:
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
A - many-to-many bidirectional
B - many-to-many bidirectional
<?xml version="1.0" encoding="Cp1252"?>
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC
"-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"