配制:Hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.hbm2ddl.auto" >update"</property>
  <property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.connection.pool_size"> 1</property>
<property name="hibernate.dialect" >org.hibernate.dialect.MySQLInnoDBDialect</property>
   <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password"></property>
   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="hibernate.connection.autocommit">false</property>
   <property name="hibernate.current_session_context_class">jta</property>
   <property name="hibernate.show_sql">true</property>
   <property name="hibernate.transaction.auto_close_session">false</property>
   <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
   <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property> 
   <mapping resource="com/my/entity/Student.hbm.xml"/>
   <mapping resource="com/my/entity/GirlFriend.hbm.xml"/>
  </session-factory>
</hibernate-configuration>Mapping:配制 Student 典型的POJO
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.my.entity"  >
  <class name="Student">
   <id name="id" column="id" >
   <generator class="native"></generator>
   </id>
   <property name="name" column="name"></property>
   <property name="" column=""></property>
   <property name="lesson" column="lesson"></property>
  </class>
</hibernate-mapping>Test用法:public class ViewMain { public static void main(String[] args) throws NamingException,
NotSupportedException, SystemException, SecurityException,
IllegalStateException, RollbackException, HeuristicMixedException,
HeuristicRollbackException {
TMService jotm = null;
UserTransaction ut = null;

// begin jotm as jta server
jotm = new Jotm(true, false);
ut = jotm.getUserTransaction();

// with jndi bind UserTransaction to JNDI provider
// Properties map = new Properties();
// map.put(Context.INITIAL_CONTEXT_FACTORY,
// "com.sun.jndi.fscontext.RefFSContextFactory");
// Context con = new InitialContext(map);
// con.bind("java:comp/UserTransaction", ut);

/* build som pojo */
Student stu = new Student();
stu.setName("zzb1");
stu.setMark(80);
stu.setLesson("java");
stu.setId(12);

Student stu2 = new Student();
stu2.setName("bbc");
stu2.setMark(100);
stu2.setLesson("c");

Student stu3 = new Student();
stu3.setName("bbcdsfds");
stu3.setMark(100);

GirlFriend gf = new GirlFriend();
gf.setName("lxlsd");

GirlFriend gf2 = new GirlFriend();
gf2.setName(null); /* build hibernate SessionFactory */
Configuration conf = new Configuration();
conf.configure("hibernate.cfg.xml");
SessionFactory sf = conf.buildSessionFactory();

/* To do for test */
try {
ut.begin();
Session session1 = sf.getCurrentSession();
ut.setTransactionTimeout(1000000000);
session1.save(gf);
session1.save(gf2);
ut.commit();
}catch(Exception e){
System.out.println("exception");
ut.rollback();
jotm.stop();
} /* close server */
finally {
if (jotm != null) {
jotm.stop();
}
}
}}
现象:我DEBUG 看过就是每次都会rollback(),所以导致SQL已经放送到了DB,但是却没有实际效果,改成MYISAM类型后,就能成功,原来是因为MYISAM是自动提交的,提交完后就不能rollback(),搞了很久,确实不什么问题了