我JPA配置多数据库源后,驼峰写法的字段无法映射到 下划线的数据库字段,
|
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")@EnableTransactionManagementpublic 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: tracespring: 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.SpringImplicitNamingStrategyeureka: 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 |
免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。
版权声明:作者保留权利,不代表本站立场。
|
|
|
|
|
|
|
|
是SQL server分页的SQL才没有打印参数,其他打印参数是正常的。 |
|
|
|
|
|
|
|