• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate is autocommiting transaction

 
Yewint Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
my problem is that hibernate is autocomming transaction . My appliation is SWT aplication in non-container managed environment . The following is my persistence.xml


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ShwePieWorldPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.leonine.shwepieworld.domain.Customer</class>
<class>com.leonine.shwepieworld.domain.CustomerPayment</class>
<class>com.leonine.shwepieworld.domain.Damage</class>
<class>com.leonine.shwepieworld.domain.DamageItem</class>
<class>com.leonine.shwepieworld.domain.Inventory</class>
<class>com.leonine.shwepieworld.domain.Item</class>
<class>com.leonine.shwepieworld.domain.ItemCategory</class>
<class>com.leonine.shwepieworld.domain.ItemConversion</class>
<class>com.leonine.shwepieworld.domain.ItemType</class>
<class>com.leonine.shwepieworld.domain.Purchase</class>
<class>com.leonine.shwepieworld.domain.PurchaseItem</class>
<class>com.leonine.shwepieworld.domain.Sale</class>
<class>com.leonine.shwepieworld.domain.SalesItem</class>
<class>com.leonine.shwepieworld.domain.Supplier</class>
<class>com.leonine.shwepieworld.domain.SupplierPayment</class>
<class>com.leonine.shwepieworld.domain.User</class>
<properties>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="admin"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/ttest"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.connection.autocommit" value="false"/>
</properties>
</persistence-unit>
</persistence>


and the following is my test snippets


ItemCategory c = new ItemCategory();
c.setName("test category");
c.setCategoriesCode("01");

EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShwePieWorldPU");
EntityManager em = emf.createEntityManager();

try{
em.getTransaction().begin();
em.persist(c);
javax.swing.JOptionPane.showMessageDialog(null, "waiting to check autocommit ");

//em.getTransaction().commit();
}catch(Exception e){
e.printStackTrace();
em.getTransaction().rollback();
}finally{
em.close();
}


In the code snippets above , i even remove the line of commiting transaction , but hibernate still autocommit the transaction . I tried adding the property "hibernate.connction.autocommit" with the value of "false" , but doesnt work .

My connection provider is ConnectorJ 5.1.6 .
Hibernate JPA 2.0

Somebody help me please and let me know if you need more info in details .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic