In my following small test class :
Session sess = new Configuration().configure("conf/hibernate.cfg.xml").buildSessionFactory().getCurrentSession();
Transaction tx = sess.beginTransaction();
System.out.println(sess.connection().getAutoCommit());
Country count = new Country ("abc", 788, "abc");
sess.save (count);
System.out.println(tx.wasRolledBack());
tx.rollback();
System.out.println(tx.wasRolledBack());
I get following output
false
false
true
which shows that tx was rolledback; but when I check DB the record is inserted there .. !!
For reference: hibernate.config.xml is
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sdl</property>
<property name="connection.username">admin</property>
<property name="connection.password">***********</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="conf/Country.hbm.xml"/>
</session-factory>
I have 8 yrs of experience but i never faced such weird problem ..
any help is highly appreciated
|