I am having a problem with rolling back a container managed transaction.
Here is the scenario...
Stateful bean (name = gb/dbSession)
calls
CMP entity bean (name = gb/sequence).
Both are deployed in same jar file with the transaction attribute set to
"Required". In order to test transactions I put a ctx.setRollbackOnly()
call in the session bean before it returns. I expected that the changed data
in the entity bean would be tossed (ie not saved to the datastore) as the
whole transaction would be rolled back. But not only was the data committed
to the database (postresql if it helps) but a call to ctx.getRollbackOnly()
just prior to and just after the ctx.setRollbackOnly() returned true both
times. What gives?
A further heavy handed approach was to force a runtime exception (a divide by
zero which is commented out in the code below) in the session bean and see if
that would rollback the transaction... but no success. I don't get it.
One possibility was that the
org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImpl was not turning off
the JDBC autocommit, but a check of the code ruled that out. So I am stumped.
Help please.
Thanks.
----------ugly details below ----------------------------------
jboss-tomcat-2.1-beta
postgresql 7.0.3
postgresql-jdbc-7.0.3-2mdk.i586.rpm
postgresql-server-7.0.3-2mdk.i586.rpm
----------deployment descriptor bits-------------------------
<ejb-jar>
....
<enterprise-beans>
<session>
<ejb-name>gb/dbSession</ejb-name>
<home>com.globalBotanical.server.DbSessionHome</home>
<remote>com.globalBotanical.server.DbSession</remote>
<ejb-class>com.globalBotanical.server.DbSessionBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
<ejb-ref>
<ejb-ref-name>gb/sequence</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.globalBotanical.server.SequenceHome</home>
<remote>com.globalBotanical.server.Sequence</remote>
<ejb-link>gb/sequence</ejb-link>
</ejb-ref>
</session>
<entity>
<description>Repository for sequence number generators</description>
<ejb-name>gb/sequence</ejb-name>
<home>com.globalBotanical.server.SequenceHome</home>
<remote>com.globalBotanical.server.Sequence</remote>
<ejb-class>com.globalBotanical.server.SequenceBean</ejb-class>
<prim-key-class>com.globalBotanical.server.SequencePK</prim-key-class>
<reentrant>False</reentrant>
<persistence-type>Container</persistence-type>
<cmp-field><field-name>name</field-name></cmp-field>
<cmp-field><field-name>val</field-name></cmp-field>
</entity>
....
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>gb/dbSession</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>gb/sequence</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
....
</assembly-descriptor>
</ejb-jar>
----------business method from session bean-------------------------
public long getNextSequence(String name, long delay) {
long next = 0;
try {
InitialContext jndiContext = new InitialContext();
Object ref = jndiContext.lookup("java:comp/env/gb/sequence");
SequenceHome home = (SequenceHome) PortableRemoteObject.narrow
(ref, SequenceHome.class);
Sequence seq = home.findByPrimaryKey(new SequencePK(name));
next = seq.getNext();
System.out.println("thinking about returning: " + next);
System.out.println(ctx.getRollbackOnly());
ctx.setRollbackOnly();
System.out.println(ctx.getRollbackOnly());
} catch (Exception e) {
e.printStackTrace();
}
// int y = 0;
// int x = 2/y;
return next;
}
----------CMP entity bean's only business method----------------
public long getNext() {
long oldval = val;
val = val + 20;
return oldval;
}
===================
Mike Finn
Tactical Executive Systems
[EMAIL PROTECTED]
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user