我有以下問題。 在我的檢票應用程序,我想使用@Transactional註解。 我所有的DAO的加載與@Component註釋;檢票春天的Hibernate事務
@Component
@Transactional(propagation = Propagation.SUPPORTS)
public class AccountHibernateDataAccessHelper implements
AccountDataAccessHelper
{
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void saveOrUpdate(T dataObject)
{
try
{
Session session = getSessionProvider().getSession();
session.saveOrUpdate(dataObject);
}
catch (HibernateException e)
{
String message = "Failed to batch save or update " + dataObject;
log.error(message, e);
}
}
@SuppressWarnings("unchecked")
public <R extends T> List<R> list(Class<R> class1)
{
Asserts.assertNotNull("class1", class1);
try
{
return createCriteria(class1).setCacheable(true)
.setCacheRegion(getQueryCacheRegion()).list();
} catch (HibernateException e)
{
String message = "Failed to get a list of" + class1;
log.error(message, e);
throw new DataAccessException(message, e);
} catch (RuntimeException e)
{
log.error(e.toString(), e);
throw new DataAccessException(e);
}
}
}
我AccountDataAccesshelper實現以下接口
public interface DataAccessHelper<T>
{
public Serializable save(T dataObject);
public void saveOrUpdate(T dataObject);
public void update(T dataObject);
public void delete(T dataObject);
public void evict(T dataObject);
}
下一頁我apllicationcontext.xml設置。
<context:component-scan base-package="nl.response.webapp" />
<context:annotation-config />
<!-- hibernate session factory -->
<bean id="sessionFactory" class="nl.response.responseframework.app.ResponseAnnotationSessionFactoryBean">
<property name="dataSource" ref="mainDataSource" />
<property name="hibernateProperties">
<map>
<entry key="hibernate.session_factory_name" value="wtxwebapp" />
<entry key="hibernate.transaction.factory_class" value="org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory" />
<entry key="hibernate.cache.query_cache_factory"
value="nl.response.responseframework.service.InvalidatableQueryCacheFactory" />
<entry key="hibernate.cache.region.factory_class"
value="nl.response.wtxwebapp.core.hibernate.WtxWebAppEhCacheRegionFactory" />
<entry key="hibernate.cache.region_prefix" value="hibernate-" />
<entry key="hibernate.generate_statistics" value="false" />
<entry key="hibernate.current_session_context_class" value="thread" />
<entry key="hibernate.cache.use_structured_entries" value="true" />
<entry key="hibernate.cache.use_query_cache" value="true" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
</map>
</property>
</bean>
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" ref="hibernate.connection.driver_class" />
<property name="jdbcUrl" ref="hibernate.connection.url" />
<property name="username" ref="hibernate.connection.username" />
<property name="password" ref="hibernate.connection.password" />
<property name="poolName" ref="hibernate.connection.username"/>
<property name="idleConnectionTestPeriodInMinutes" value="60" />
<property name="idleMaxAgeInMinutes" value="240" />
<property name="maxConnectionsPerPartition" value="50" />
<property name="minConnectionsPerPartition" value="5" />
<property name="partitionCount" value="2" />
<property name="poolAvailabilityThreshold" value="10" />
<property name="acquireIncrement" value="4" />
<property name="statementsCacheSize" value="50" />
<property name="releaseHelperThreads" value="3" />
<property name="serviceOrder" value="LIFO" />
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="mainDataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
爲隨後
public Session getSession()
{
getSessionFactory().openSession();
}
當我使用上述會議梅索德沒有被提交,一個巨大的批量我得到一個錯誤,因爲連接的arent正確關閉會話提供商提供的會話。
當我使用getSessionFactory.getCurrentSession()我收到以下錯誤
個createCriteria無效無活動事務
我在想什麼?即時嘗試讓這個工作已經好幾天了,即時離開選項:S
當我加載實體列表時,我得到'createCriteria無效,沒有活動事務'錯誤 – 2012-02-08 14:25:58