UserTranaction utx = null;
try {
Context ctx = new InitialContext();
utx = (UserTransaction) ctx.lookup("java:/comp/UserTransaction");
utx.begin();
UserHome userHome = (UserHome) ctx.lookup("User");
User user = userHome.findByPrimaryKey(Integer.valueOf("9"));
user.setName("user1");
ClassanduserHome home = (ClassanduserHome) ctx.lookup("Classanduser");
Classanduser classanduser = home.create(Integer.valueOf("2"), Integer.valueOf("2"));
utx.commit();
System.out.println(classanduser.getClassID());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
Classanduser classanduser = home.create(Integer.valueOf("2"), Integer.valueOf("2")); throw Exception
user.setName("user1") can rollback
but when replace user.setName("user1") with
user.remove() or userHome.create("user2")
it can't rollback
who can help me please!
Most likely it is the type of exception you are
throwing.
Just a guess, you posted no about why you
expect the transaction to be rolled back or
otherwise.
Regards,
Adrian