Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Kubernetes
- gson
- docker
- log4j2
- tibero
- wildfly
- Git
- IntelliJ
- NCP
- JavaScript
- kubectl
- useEffect
- MySQL
- nginx
- springboot
- jetbrains
- gradle
- BPMN
- LOG4J
- mybatis
- database
- react
- intellijIDEA
- JPA
- nodejs
- dbeaver
- Spring
- Java
- Windows
- VSCode
Archives
- Today
- Total
두 손끝의 창조자
persistence.xml 없이 EntityManagerFactory 설정하기 본문
persistence.xml 없이 자바로 속성 설정해서 사용하려면
@Bean
public EntityManagerFactory entityManagerFactoryForMysql(DataSource dataSource) {
final Properties properties = new Properties();
properties.put( "hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect" ); // MySql5x 쓴다면
properties.put( "hibernate.user_sql_comments", "true" );
properties.put( "hibernate.format_sql", "true" );
properties.put( "hibernate.hbm2ddl.auto", "create" );
properties.put( "hibernate.physical_naming_strategy", "[물리이름전략개체]" );
final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setPersistenceUnitName("[유닛이름]");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactoryBean.setJpaProperties(properties);
entityManagerFactoryBean.setPackagesToScan("[엔티티스캔할 패키지]");
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
entityManagerFactoryBean.afterPropertiesSet(); // 모든 설정정보 set 후 꼭 호출해야함 !!
return entityManagerFactoryBean.getObject();
}
반응형
Comments