Another "removing bean lock and it has tx set" IllegalStateE
vorlon Nov 13, 2002 4:37 PMHi,
I get an IllegalStateException when calling a 1.1 CMP Entity bean instance running on JBoss 3.0.4 (also 3.0.3) with message "removing bean lock and it has tx set" from QueuedPessimisticEJBLock. I already found out that this often happens when people do not correctly implement equals() and hashCode() in the PK class (I also have a composite PK class). My equals() and hashCode() implementations look okay to me, so I think that's not the problem (maybe I am wrong).
My client's code is this:
try {
UserNetworkConnectionPK pk = new UserNetworkConnectionPK(objID);
System.out.println("PK is " + pk.toString() + ", hashCode is " + pk.hashCode());
conn = connHome.findByPrimaryKey(pk);
System.out.println("Found connection");
conn.prepareRemove(userID);
System.out.println("Prepared remove");
conn.remove();
System.out.println("Removed connection");
}
catch (Exception e) {
log.error("Caught Exception while trying to remove UserNetworkConnection "
+ objID + "!", e);
}
The client crashes when it tries to call conn.prepareRemove(), which checks if the user is allowed to call this method:
PK is 2-35576, hashCode is -161032
Found connection
[ERROR,2002-11-13 12:17:55,178,DeleteRFCProcessor] Caught Exception while trying
to remove UserNetworkConnection 2-35576!
java.rmi.ServerException: RemoteException occurred in server thread; nested exce
ption is:
javax.transaction.TransactionRolledbackException: removing bean lock and
it has tx set!UserNetworkConnection 2-35576; nested exception is:
java.lang.IllegalStateException: removing bean lock and it has tx set!Us
erNetworkConnection 2-35576
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Sour
ce)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvo
kerProxy.java:138)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
a:108)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
java:77)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:8
0)
at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:1
16)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
at $Proxy28.prepareRemove(Unknown Source)
at com.polypol.MessageHandling.DeleteRFCProcessor.process(DeleteRFCProce
ssor.java:92)
at com.polypol.MessageHandling.DeleteRFCProcessor.start(DeleteRFCProcess
or.java:56)
at com.polypol.Dispatcher.PPRequestHandler.handleRequest(PPRequestHandle
r.java:822)
at com.polypol.Dispatcher.PPRequestHandler.run(PPRequestHandler.java:81)
at java.lang.Thread.run(Thread.java:536)
Caused by: javax.transaction.TransactionRolledbackException: removing bean lock
and it has tx set!UserNetworkConnection 2-35576; nested exception is:
java.lang.IllegalStateException: removing bean lock and it has tx set!Us
erNetworkConnection 2-35576
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
rceptor.java:230)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
torCMT.java:232)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
0)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
java:130)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:479)
at org.jboss.ejb.Container.invoke(Container.java:712)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1046)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
382)
at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
... 1 more
Caused by: java.lang.IllegalStateException: removing bean lock and it has tx set
!UserNetworkConnection 2-35576
at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedP
essimisticEJBLock.java:427)
at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:107)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
tor.java:124)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
Interceptor.java:69)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
rceptor.java:107)
... 19 more
I also tried to lookup and use a UserTransaction, but this doesn't change anything, except that the DB (MySQL) will not be left in an unconsistent state anymore.
The PK class is implemented as follows:
public class UserNetworkConnectionPK implements Serializable {
private static final Category log = Category.getInstance("UserNetworkConnectionPK");
public long InitiatorID;
public long AcceptorID;
public UserNetworkConnectionPK(String ID) {
int p = -2;
String initiator = null;
String acceptor = null;
try {
p = ID.indexOf("-");
initiator = ID.substring(0, p);
acceptor = ID.substring(p+1);
this.InitiatorID = Long.parseLong(initiator);
this.AcceptorID = Long.parseLong(acceptor);
}
catch (NumberFormatException e) {
log.error("Exception in UserNetworkConnectionPK(" + ID + ")!", e);
log.error("p is " + p);
log.error("initiator is " + initiator);
log.error("acceptor is " + acceptor);
throw e;
}
}
public UserNetworkConnectionPK() {}
public int hashCode() {
return (((short) InitiatorID) << 16) ^ ((short) AcceptorID);
}
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof UserNetworkConnectionPK) {
UserNetworkConnectionPK comp = (UserNetworkConnectionPK) obj;
if (this.InitiatorID == comp.InitiatorID && this.AcceptorID == comp.InitiatorID) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
/**
* Return a string representation of the object
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(this.InitiatorID);
buffer.append("-");
buffer.append(this.AcceptorID);
return buffer.toString();
}
}
TX attribute of UserNetworkConnection.prepareRemove() is configured as Supports:
<container-transaction>
<ejb-name>UserNetworkConnection</ejb-name>
<method-intf>Remote</method-intf>
<method-name>prepareRemove</method-name>
<method-params>
<method-param>long</method-param>
</method-params>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
Everything seems to be okay. Changing the transaction attributes did not help.
Does anybody know what causes the IllegalStateException?
Thanks in advance,
Michael