J2EE tutorial on JBoss
atorres May 8, 2002 1:23 PMHi.
I´m trying to pass an example tutorial from Sun to JBoss, an example using BMP and one to many relationship.
The example is the salesrep BMP.
I managed to execute it fine after some changes on the xml deployment and component lookup names like :
Object objref = initial.lookup("java:comp/env/ejb/SimpleSalesRep");
becames
Object objref = initial.lookup("SalesRepBean");
Ok. I access the database and shows up the data. But when it changes the relationship of data, ( I haven´t changed that part of the example from sun) it hangs until I stop the server.
I used autocommit = false. Them I changed to true, and I got:
Caught an exception.
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
javax.transaction.TransactionRolledbackException: removing bean lock and it has tx set!; nested exception is:
java.lang.IllegalStateException: removing bean lock and it has tx set!
javax.transaction.TransactionRolledbackException: removing bean lock and it has tx set!; nested exception is:
java.lang.IllegalStateException: removing bean lock and it has tx set!
java.lang.IllegalStateException: removing bean lock and it has tx set!
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.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invoke(Unknown Source)
at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:357)
at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(EntityProxy.java:133)
at $Proxy2.setSalesRepId(Unknown Source)
at SalesRepClient.main(SalesRepClient.java:47)
Here is the client code (You could get it from sun)
/*
*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class SalesRepClient {
public static void main(String[] args) {
try {
Context initial = new InitialContext();
// Object objref = initial.lookup("java:comp/env/ejb/SimpleSalesRep");
Object objref = initial.lookup("SalesRepBean");
SalesRepHome salesHome =
(SalesRepHome)PortableRemoteObject.narrow(objref,
SalesRepHome.class);
objref = initial.lookup("CustomerBean");
CustomerHome customerHome =
(CustomerHome)PortableRemoteObject.narrow(objref,
CustomerHome.class);
Customer buzz = customerHome.create("844", "543", "Buzz Murphy");
Collection c = customerHome.findBySalesRep("543");
Iterator i = c.iterator();
while (i.hasNext()) {
Customer customer = (Customer)i.next();
String customerId = (String)customer.getPrimaryKey();
System.out.println("customerId = " + customerId);
}
System.out.println();
Customer mary = customerHome.findByPrimaryKey("987");
mary.setSalesRepId("543");
Customer x = customerHome.findByPrimaryKey("987");
SalesRep janice = salesHome.findByPrimaryKey("543");
ArrayList a = janice.getCustomerIds();
i = a.iterator();
while (i.hasNext()) {
String customerId = (String)i.next();
Customer customer = customerHome.findByPrimaryKey(customerId);
String name = customer.getName();
System.out.println(customerId + ": " + name);
}
System.exit(0);
} catch (Exception ex) {
System.err.println("Caught an exception." );
ex.printStackTrace();
}
}
}
I used MS-SQL Server as database with MS drivers.
Thanks in advance