jpa和mybadis混合事务不起作用了(之前是可以用的)会是什么影响了,后面有加入spring cloud和hibernate 自定义Id的生成器

minga1 2017-11-17 11:49:52
package com.ecaicn.cjyun.app.config;

import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Properties;

import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef="entityManagerFactory", transactionManagerRef="jpaTransactionManager", basePackages = "com.ecaicn.cjyun.provider.repository")
@MapperScan("com.ecaicn.cjyun.provider.mapper")//Mapper扫描
public class DaoConfig {

private static final String NAMING_STRATEGY = "hibernate.physical_naming_strategy";
private static final String SNAKE_STRATEGY_IMPL = "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy";

@Autowired
DataSource dataSource;

@Bean
public JpaVendorAdapter jpaVendorAdapter(){
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.MYSQL);
adapter.setShowSql(true);
adapter.setGenerateDdl(false);
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
return adapter;
}

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource){
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setDataSource(dataSource);
factory.setJpaVendorAdapter(jpaVendorAdapter());
factory.setPackagesToScan("com.ecaicn.cjyun.model.entity");
factory.setJpaProperties(hibernateProperties());
factory.afterPropertiesSet();
return factory;
}

@Bean
public JpaTransactionManager jpaTransactionManager(DataSource dataSource) {
JpaTransactionManager jtm = new JpaTransactionManager();
jtm.setEntityManagerFactory( entityManagerFactory(dataSource).getObject());
return jtm;
}

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
LogFactory.useStdOutLogging();
//添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
sessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
return sessionFactory.getObject();
} catch (Exception e) {
throw new RuntimeException("sqlSessionFactory init fail", e);
}
}

private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put(NAMING_STRATEGY, SNAKE_STRATEGY_IMPL);
return properties;
}

}

...全文
191 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
源码直接下载地址: https://pan.quark.cn/s/1c143f32ee83 华为作为全球领先的通信设备供应商,其产品系列广泛涉及各类网络设备,其中包括我们接下来要探讨的上网卡产品。华为上网卡驱动程序是一种专门为华为品牌旗下多种型号上网卡开发的软件模块,其主要功能在于保障这些设备与计算机操作系统的无缝对接。涉及的型号涵盖EC8189、EC226、EC169C、EC360、EC1260、EC1261、EC189、EC122、EC150以及EC168,这些均是由华为公司推出的移动宽带调制解调器,旨在通过移动网络实现便捷的互联网接入服务。驱动程序在计算机系统中的地位举足轻重,它充当了硬件设备与操作系统之间的媒介,负责对硬件设备发出的指令进行解读和执行,并将操作系统的指令传递给硬件设备。华为上网卡驱动程序的及时更新和精准安装是保障设备稳定运作和性能达到最优的关键因素。"天翼宽带安装程序V1.3.3.exe"是由中国电信提供的一个整合性软件包,内含华为上网卡的驱动程序及配套的管理工具。用户可借助此安装程序来执行华为上网卡的相关驱动安装及更新,同步享受中国电信的3G或4G网络服务。版本标识V1.3.3代表软件经过迭代优化,通常包含了对错误的修正、性能的改善以及新功能的引入。 "SetupInfo.xml"作为安装程序的配置文档,其中收录了安装流程中的各项设定和元数据信息,例如安装流程、文件定位、依赖条件等。它是安装程序在执行时参照和遵循的纲领,旨在确保安装流程按既定方案进行。文件名"CT_HW_EVDO_Driver"或许指向华为的EVDO(Evolution-Data Optimized)驱动程序,EVDO是一种3G无线通信规范,具备高速数据传输的特性。该驱动可...

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧