我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


weixin_慕数据1513485
浏览 1933回答 1
1回答

weixin_慕数据1513485

是SQL server分页的SQL才没有打印参数,其他打印参数是正常的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
MySQL