Problem with 1-Many Relationships
tdang Jun 5, 2003 9:42 AMHi all,
I have 2 ejbs: Category and Product. They have the 1-Many Relationship. I could deploy my beans and it runs well, until I add a product to a category like this:
public void addProduct(String category, String product)
throws FinderException, CreateException {
try {
Category c = createCategoryHome().findByPrimaryKey(category);
Product p = createProductHome().create(product);
c.getProductBeans().add(p);
} catch (NamingException ne) {
throw new EJBException(ne);
}
}
I got the following errors from jboss:
java.lang.reflect.UndeclaredThrowableException: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:138)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:111)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
at $Proxy1.addProduct(Unknown Source)
at org.eStore.test.TestMySQL.main(TestMySQL.java:21)
I am using JBoss3.0.4
Every help would be appreciated.
Thanks in advance.