I'm trying to force hibernate to rollback a transaction, as a test. I've included the code for doing so below. My problem is, even if I call ctx.setRollBackOnly() a record for the object still exists in the database after the method executes. I'm testing this method via a remote call to a Stateless Session Bean.
Hibernate version: 2.1.8
JBoss version: 4.0.1sp1
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.lg.hibernate.dbo.UserCredentials"
table="user_credentials"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Integer"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<property
name="uid"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="uid"
length="32"
/>
<property
name="userName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="user_name"
length="50"
not-null="true"
unique="true"
/>
<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="password"
length="50"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserCredentials.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
sections from ejb-jar.xml
Code:
<container-transaction >
<method >
<ejb-name>UserFacade</ejb-name>
<method-intf>Remote</method-intf>
<method-name>createUser</method-name>
<method-params>
<method-param>com.lg.hibernate.dbo.UserCredentials</method-param>
</method-params>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
Code between sessionFactory.openSession() and session.close():Code:
public User createUser(UserCredentials creds)
throws DataStoreException,
UserExistsException {
try {
Session sess = HibernateContext.getSession(LG_SESSION);
sess.save(creds);
ctx.setRollbackOnly();
throw new EJBException("forced rollback");
} catch (HibernateException e) {
ctx.setRollbackOnly();
throw new UserExistsException(e.getMessage(), e);
}
return null;
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL 4.0.24
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: