Skip to content

Instantly share code, notes, and snippets.

@anandrajneesh
Created November 7, 2017 02:14
Show Gist options
  • Save anandrajneesh/26c03358a04554a6a05758a2899a5ed7 to your computer and use it in GitHub Desktop.
Save anandrajneesh/26c03358a04554a6a05758a2899a5ed7 to your computer and use it in GitHub Desktop.
Spring Boot Hibernate

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

@Autowired
private EntityManagerFactory entityManagerFactory;

@Bean
public SessionFactory getSessionFactory() {
if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
throw new NullPointerException("factory is not a hibernate factory");
}
return entityManagerFactory.unwrap(SessionFactory.class);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment