解决方案 »

  1.   

    把完整配置文件贴出来吧  
    <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
        <context:component-scan base-package="com.heping.oa" /> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>
    <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes">
    <list>
    <value>text/html;charset=UTF-8</value>
    </list>
    </property>
    </bean>

    <!-- Jpa Entity Manager 配置 -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
    <property name="mappingResources">  
                <list>  
                   <value>com/heping/oa/entity/main/hbm/Division.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Employee.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Hospital.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Keyword.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Role.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Resource.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Module.hbm.xml</value>
                   <value>com/heping/oa/entity/main/hbm/Spreader.hbm.xml</value>
                </list>  
            </property>
    <property name="jpaProperties">
    <props>
    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.SingletonEhCacheRegionFactory</prop>
    <prop key="net.sf.ehcache.configurationResourceName">cache/ehcache-hibernate-local.xml</prop>
    <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property>
    </bean>
    <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="databasePlatform">
    <bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
    <constructor-arg ref="dataSource"/>
    </bean>
    </property>
    </bean>

    <!-- 事务管理器配置, Jpa单数据源事务 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!-- 定义aspectj -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

    <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties" />
    <!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <!-- Connection Info -->
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="defaultAutoCommit" value="false" />
    </bean>
      

  2.   

     贴下 我JAVA  DAOIMPL代码 
    @Repository("baseDao")
    public class BaseDaoImpl<T> implements BaseDao<T> {

    private EntityManagerFactory entityManagerFactory; public EntityManagerFactory getEntityManagerFactory() {
    return entityManagerFactory;
    }

    @Autowired
    public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
    this.entityManagerFactory = entityManagerFactory;
    } private EntityManager getCurrentSession() {
    return this.entityManagerFactory.createEntityManager();
    } @Transactional
    public Serializable save(T o) {
    this.getCurrentSession().persist(o);
    return null;
    }
    public T get(Class<T> c, Serializable id) {
    return (T) this.getCurrentSession().getReference(c, id);
    }
    public T get(String hql) {
    Query q = this.getCurrentSession().createQuery(hql);
    List<T> l = q.getResultList();
    if (l != null && l.size() > 0) {
    return l.get(0);
    }
    return null;
    }
    public T get(String hql, Map<String, Object> params) {
    Query q = this.getCurrentSession().createQuery(hql);
    if (params != null && !params.isEmpty()) {
    for (String key : params.keySet()) {
    q.setParameter(key, params.get(key));
    }
    }
    List<T> l = q.getResultList();
    if (l != null && l.size() > 0) {
    return l.get(0);
    }
    return null;
    }
    public void delete(T o) {
    this.getCurrentSession().remove(o);
    }
    public void update(T o) {
    this.getCurrentSession().refresh(o);
    }
    public void saveOrUpdate(T o) {
    this.getCurrentSession().refresh(o);
    }
    public List<T> find(String hql) {
    Query q = this.getCurrentSession().createQuery(hql);
    return q.getResultList();
    }
    public List<T> find(String hql, Map<String, Object> params) {
    Query q = this.getCurrentSession().createQuery(hql);
    if (params != null && !params.isEmpty()) {
    for (String key : params.keySet()) {
    q.setParameter(key, params.get(key));
    }
    }
    return q.getResultList();
    }
    public List<T> find(String hql, Map<String, Object> params, int page, int rows) {
    Query q = this.getCurrentSession().createQuery(hql);
    if (params != null && !params.isEmpty()) {
    for (String key : params.keySet()) {
    q.setParameter(key, params.get(key));
    }
    }
    return q.setFirstResult((page - 1) * rows).setMaxResults(rows).getResultList();
    }
    public List<T> find(String hql, int page, int rows) {
    Query q = this.getCurrentSession().createQuery(hql);
    return q.setFirstResult((page - 1) * rows).setMaxResults(rows).getResultList();
    }
    public Long count(String hql) {
    Query q = this.getCurrentSession().createNativeQuery(hql);
    return (Long) Long.valueOf(q.getSingleResult().toString());
    }
    public Long count(String hql, Map<String, Object> params) {
    Query q = this.getCurrentSession().createQuery(hql);
    if (params != null && !params.isEmpty()) {
    for (String key : params.keySet()) {
    q.setParameter(key, params.get(key));
    }
    }
    return Long.valueOf(q.getSingleResult().toString());
    }
    public int executeHql(String hql) {
    Query q = this.getCurrentSession().createQuery(hql);
    return q.executeUpdate();
    }
    public int executeHql(String hql, Map<String, Object> params) {
    Query q = this.getCurrentSession().createQuery(hql);
    if (params != null && !params.isEmpty()) {
    for (String key : params.keySet()) {
    q.setParameter(key, params.get(key));
    }
    }
    return q.executeUpdate();
    }
      

  3.   

    事物应该配置在Services层上吧,你配置 在DAO层不可以的