67,550
社区成员




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
>
<!-- default-lazy-init="true" default-autowire="byName" -->
<!-- ============================================== -->
<!-- =========== Spring 公用配置 =================== -->
<!-- ============================================== -->
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:hibernate.properties</value>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- 安全的路径jdbc:mysql://127.0.0.1:3306/va66?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8 -->
<property name="jdbcUrl" value="${hibernate.connection.url}" />
<property name="driverClass" value="${hibernate.connection.driver_class}" />
<property name="user" value="${hibernate.connection.username}" />
<property name="password" value="${hibernate.connection.password}" />
<property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
<property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
<property name="minPoolSize" value="${c3p0.minPoolSize}" />
<property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
<property name="maxStatements" value="${c3p0.maxStatements}" />
<property name="numHelperThreads" value="${c3p0.numHelperThreads}" />
<property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/gwtjs/model/Article.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<!-- cache -->
<prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
<prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<!-- advice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" read-only="true" />
<!-- <tx:method name="*" no-rollback-for="java.lang.Throwable"/> <tx:method
name="*" read-only="true" /> -->
</tx:attributes>
</tx:advice>
<!-- aop -->
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.gwtjs.dao.impl.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
<context:annotation-config />
<context:component-scan base-package="com.gwtjs">
<!-- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
</context:component-scan>
<import resource="classpath:spring-cxf-config.xml" />
<!-- <import resource="config/spring/spring-tags.xml"/> -->
</beans>
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import com.gwtjs.dao.EntityDao;
import com.gwtjs.model.Pager;
import com.gwtjs.utils.model.QueryCondition;
@Repository(value = "entityDao")
public class EntityDaoImpl<T, PK extends Serializable> implements
EntityDao<T, PK> {
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
/**
* @return 在session工厂获取当前session,这是hibernate4开始要求的做法
*/
public Session getSession() {
// 事务必须(Required)是开启的,否则获取不到
return sessionFactory.getCurrentSession();
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-config.xml"})
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class EntityDaoSaveTest {
@Resource(name = "entityDao")
private static EntityDao<Article,Integer> entityDao;
@Test
public void testSave(){
System.out.println(entityDao);
}
}
<property name="javax.persistence.validation.mode">none</property>