Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `public class Hibernateutil {
- private static final SessionFactory sessionFactory;
- static {
- try {
- sessionFactory = new Configuration()
- .buildSessionFactory();
- } catch (Throwable ex) {
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- `
- `@Repository
- public class StudentRepository1 {
- SessionFactory factory = Hibernateutil.getSessionFactory();
- Session currentSession =factory.getCurrentSession();
- //do something
- }`
- `# Details for our datasource
- spring:
- datasource:
- url: jdbc:postgresql://localhost:5432/postgres
- username: postgres
- password: postgres
- driver-class-name: org.postgresql.Driver
- # Hibernate properties
- jpa:
- properties:
- hibernate:
- dialect: org.hibernate.dialect.PostgreSQL95Dialect
- #current_session_context_class: thread
- show-sql: false
- hibernate.ddl-auto:
- #application properties
- application:
- name: hibernate_demo
- server:
- port: 10091`
- `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
- ... 39 common frames omitted`
- `
- dependencies {
- //compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.6.RELEASE'
- compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.1.Final'
- compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
- compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.9.RELEASE'
- compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'
- }
Add Comment
Please, Sign In to add comment