本文介绍了事务超时不能用于与oracle的休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题为oracle上的hibernate设置事务超时。它不起作用。任何人都可以帮忙吗?
SaveOrUpdate在规定的10秒内不会返回。它会挂起很长时间。
我正在使用Oracle 10r2。
Hibernate配置文件
<冬眠-结构>
< session-factory>
< property name =connection.driver_class> oracle.jdbc.driver.OracleDriver< / property>
< property name =connection.url> jdbc:oracle:thin:@ 9.9.9.9:1521:orcl< / property>
< property name =connection.username> foouser< / property>
< property name =connection.password> foopass< / property>
< property name =hibernate.c3p0.min_size> 5< / property>
< property name =hibernate.c3p0.max_size> 20< / property>
< property name =dialect> org.hibernate.dialect.Oracle9Dialect< / property>
< property name =current_session_context_class>线程< / property>
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
< property name =show_sql> false< / property>
< mapping resource =foo.hbm.xml/>
< / session-factory>
< / hibernate-configuration>
Hibernate class
public class foo implements Serializable
{
...
public void save()throws Exception
{
Session dbSession = null;
交易tran = null;
try
{
dbSession = PersistenceMgr.getPersistenceMgr()。getDbSession();
tran = dbSession.beginTransaction();
tran.setTimeout(10); // 10秒
dbSession.saveOrUpdate(this);
tran.commit();
catch(HibernateException e)
{
if(tran!= null)
{
try {tran.rollback();}
$ catch(HibernateException he){}
}
...
}
finally
{
if(dbSession!= null)
{
try {dbSession.close();}
catch(HibernateException e){}
}
}
}
}
解决方案
在事务启动之前需要设置超时。
而不是
tran = dbSession.beginTransaction();
tran.setTimeout(10); // 10秒
try
tran = dbSession.getTransaction();
tran.setTimeout(10);
tran.begin();
I am having problem setting the transaction timeout for hibernate on oracle. It does not work.Can anyone help?The "SaveOrUpdate" will not return within the stated 10 seconds. It will hang for a very long time.I am using Oracle 10r2.
Hibernate Configuration File
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@9.9.9.9:1521:orcl</property>
<property name="connection.username">foouser</property>
<property name="connection.password">foopass</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Mapping files -->
<mapping resource="foo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Hibernate class
public class foo implements Serializable
{
...
public void save() throws Exception
{
Session dbSession = null;
Transaction tran = null;
try
{
dbSession = PersistenceMgr.getPersistenceMgr().getDbSession();
tran = dbSession.beginTransaction();
tran.setTimeout(10); // 10 seconds
dbSession.saveOrUpdate(this);
tran.commit();
}
catch (HibernateException e)
{
if(tran!=null)
{
try{tran.rollback();}
catch(HibernateException he){}
}
...
}
finally
{
if( dbSession != null )
{
try{dbSession.close();}
catch(HibernateException e){}
}
}
}
}
解决方案
The timeout needs to be set before the transaction is started.
instead of
tran = dbSession.beginTransaction();
tran.setTimeout(10);// 10 seconds
try
tran = dbSession.getTransaction();
tran.setTimeout(10);
tran.begin();
这篇关于事务超时不能用于与oracle的休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!