当我在 java swing 中运行我的休眠项目时,它首先工作。但是当我等待一段时间并收到类似 org.hibernate.TransactionException: rollback failed.. 的错误时,请告诉我一个解决方案。
这是我的错误
Aug 16, 2013 10:52:21 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08S01
Aug 16, 2013 10:52:21 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Communications link failure
The last packet successfully received from the server was 89,371 milliseconds ago.
The last packet sent successfully to the server was 1 milliseconds ago.
Exception in thread "AWT-EventQueue-0" org.hibernate.TransactionException: rollback failed
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:215) at com.softroniics.queenpharma.services.PurchaseOrderService.showAllPurchase(PurchaseOrderService.java:131)
这是我的休眠 cfg 文件
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://queenpharma.db.11583306.hostedresource.com/queenpharma</property>
<property name="connection.username">queenpharma</property>
<property name="connection.password">Queenpharma#1</property>
<property name="connection.pool_size">1</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="connection.autocommit">false</property>
<property name="hibernate.c3p0.max_size">1</property>
<property name="hibernate.c3p0.min_size">0</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">1000</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<mapping class="com.softroniics.queenpharma.model.LoginModel" />
<mapping class="com.softroniics.queenpharma.model.PurchaseCompanyModel" />
- - 等等 - - -
这是我的一些代码
session = sessionFactory.openSession();
StockModel stockModel = null;
try {
tx = session.beginTransaction();
Iterator<StockModel> iterator = session
.createQuery("FROM StockModel where productid='" + id + "'")
.list().iterator();
if(iterator.hasNext()){
stockModel = iterator.next();
}
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();