//相当于sqlSessionFactoryBean这个类的配置
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(dataSource);
//扫描加了@Entity的类
bean.setPackagesToScan("com.wgc.persons.demo.entity");
bean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties properties = new Properties();
//就在启动服务是,它会查看我们实体中的字段是否与数据库一致,如果不一致,它会自动修改,
//如果把update该create , 它会自动在数据库创建相对应的表
properties.setProperty("hibernate.hbm2ddl.auto", "update");
//是不是显示sql语句
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("hibernate.format_sql", "true");
/* MySQLDialect 如果是使用MariaDB就要改为 MariaDBDialect */
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
bean.setJpaProperties(properties);
return bean;
}
标签:Hibernate,Spring,bean,hibernate,sql,setProperty,new,Data,properties
From: https://blog.51cto.com/u_14682436/6317451