jpa字段和mysql驼峰无法转换_我JPA配置多数据库源后,驼峰写法的字段无法映射到 下划线的数据库字段, 也无法打印sql参数...

package com.example.msmultipledatasource.configuration;

import com.zaxxer.hikari.HikariDataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.Primary;

import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import org.springframework.orm.jpa.JpaTransactionManager;

import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

import org.springframework.orm.jpa.vendor.Database;

import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;

import org.springframework.transaction.PlatformTransactionManager;

import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

import java.util.Properties;

@Configuration

@EnableJpaRepositories(

basePackages = {"com.example.msmultipledatasource.dao.first"},// 1. dao 层所在的包

entityManagerFactoryRef = "firstEntityManagerFactory")

@EnableTransactionManagement

public class FirstDataSourceConfigure {

@Bean

@Primary

public LocalContainerEntityManagerFactoryBean firstEntityManagerFactory() {

LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();

factoryBean.setDataSource(firstDataSource());

HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();

jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.SQLServer2008Dialect");

jpaVendorAdapter.setDatabase(Database.SQL_SERVER);

jpaVendorAdapter.setShowSql(true);

factoryBean.setJpaVendorAdapter(jpaVendorAdapter);

// 2. 实体类所在的包

factoryBean.setPackagesToScan("com.example.msmultipledatasource.domain.first");

return factoryBean;

}

@Bean

@Primary

@ConfigurationProperties("app.datasource.first")

public DataSourceProperties firstDataSourceProperties() {

return new DataSourceProperties();

}

@Bean

@Primary

@ConfigurationProperties("app.datasource.first.configuration")

public DataSource firstDataSource() {

return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();

}

}logging:

level:

org.hibernate.type.descriptor.sql.BasicBinder: trace

spring:

application:

name: msmultipledatasource

jpa:

show-sql: true

hibernate:

naming:

physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

eureka:

client:

service-url:

defaultZone: http://127.0.0.1:8761/eureka/

app:

datasource:

first:

driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ckgl

username: sa

password:

second:

driver-class-name: com.mysql.jdbc.Driver

url: jdbc:mysql://127.0.0.1:3306/springcloud_sell?characterEncoding=utf-8&useSSL=false

username: root

password: 123456

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值