fuint-framework/fuint-base/src/main/java/com/fuint/base/config/JpaConfig.java

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.fuint.base.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.fuint.base.dao.BaseRepositoryFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.Properties;

/**
 * spring data jpa 配置
 * <p/>
 * Created by FSQ
 * Contact wx fsq_better
 */
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.*.*.dao.repositories", repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager")
public class JpaConfig {

    private static final Logger logger = LoggerFactory.getLogger(JpaConfig.class);

    @Autowired
    private Environment env;


    @Bean(name = "entityManagerFactory")
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(Boolean.TRUE);
        vendorAdapter.setShowSql(Boolean.TRUE);
        factory.setDataSource(dataSource());
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("com.*.*.dao.entities");
        factory.setPersistenceUnitName("defaultPersistenceUnit");
        Properties jpaProperties = new Properties();
        jpaProperties.put("hibernate.hbm2ddl.auto", env.getProperty("jpa.hibernate.hbm2ddl.auto"));
        jpaProperties.put("hibernate.dialect", env.getProperty("jpa.hibernate.dialect"));
        jpaProperties.put("hibernate.show_sql", env.getProperty("jpa.hibernate.show.sql"));
        jpaProperties.put("hibernate.format_sql", true);
        jpaProperties.put("hibernate.event.merge.entity_copy_observer", "allow");
        //不区分数据库表字段大小写
        jpaProperties.put("hibernate.naming_strategy", "hibernate.ejb.naming_strategy");
        factory.setJpaProperties(jpaProperties);
        factory.afterPropertiesSet();
        factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
后面还有 45 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。