日期:2014-05-19 浏览次数:20629 次
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id = "txAdice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true"/>
<tx:method name="query*" propagation="REQUIRED" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="pointCut" expression="execution(* com.test..service.impl.*.*(..))" />
<aop:advisor pointcut-ref="pointCut" advice-ref="txAdice"/>
</aop:config>
/**
* Copyright (C) 2012 http://blog.csdn.net/Just_szl
*
* 修订历史记录:
*
* Revision 1.0 2012-11-15 Geray 创建。
*
*/
package com.hibernate.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
/**
*
* @author <a href="mailto:just_szl@hotmail.com"> Geray</a>
* @version 1.0,2012-11-15
*/
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static Configuration configuration;
static
{
try {
configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();