Hi,
I am using Hibernate inside the JBoss server. Referring to the Documentation, the following fragment of code (inside a Stateless Beans)
should use the JTA without having code to deal with transactions. The method uses "RequiresNew".
I was expecting hibernate not to store the dataset into the DB, but
the user has been made persistent, although the Transaction is marked as "rollback".
Furthermore, debugging the application, I could see that the INSERT statement was send to the DB after session.save( user ); has been invoked
and NOT after the completion of the transaction.
Any Thoughts?
Code:
public User createUser(String firstname, String lastname) throws Exception {
Context ctx = new InitialContext();
SessionFactory sf = (SessionFactory)
ctx.lookup( "java:/hb/SessionFactory" );
Session session = sf.getCurrentSession();
User user = new User();
user.setFirstname(firstname);
user.setLastname(lastname);
session.save(user);
this.ctx.setRollbackOnly();
return user;
}
Debug message from the JBoss server:
Code:
[STDOUT] Hibernate: insert into User_hbm_tbl (firstname_col, lastname_col) values (?, ?)