Guest User

Untitled

a guest
Jun 1st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. `public class Hibernateutil {
  2.  
  3. private static final SessionFactory sessionFactory;
  4. static {
  5. try {
  6. sessionFactory = new Configuration()
  7. .buildSessionFactory();
  8. } catch (Throwable ex) {
  9. System.err.println("Initial SessionFactory creation failed." + ex);
  10. throw new ExceptionInInitializerError(ex);
  11. }
  12. }
  13.  
  14. public static SessionFactory getSessionFactory() {
  15. return sessionFactory;
  16. }
  17. `
  18.  
  19. `@Repository
  20. public class StudentRepository1 {
  21.  
  22.  
  23. SessionFactory factory = Hibernateutil.getSessionFactory();
  24.  
  25. Session currentSession =factory.getCurrentSession();
  26.  
  27. //do something
  28. }`
  29.  
  30. `# Details for our datasource
  31. spring:
  32. datasource:
  33. url: jdbc:postgresql://localhost:5432/postgres
  34. username: postgres
  35. password: postgres
  36. driver-class-name: org.postgresql.Driver
  37. # Hibernate properties
  38. jpa:
  39. properties:
  40. hibernate:
  41. dialect: org.hibernate.dialect.PostgreSQL95Dialect
  42. #current_session_context_class: thread
  43. show-sql: false
  44. hibernate.ddl-auto:
  45. #application properties
  46. application:
  47. name: hibernate_demo
  48. server:
  49. port: 10091`
  50.  
  51. `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
  52. at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  53. at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  54. at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  55. at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  56. at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  57. at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
  58. ... 39 common frames omitted`
  59.  
  60. `
  61.  
  62. dependencies {
  63. //compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.6.RELEASE'
  64. compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.1.Final'
  65. compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
  66. compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.9.RELEASE'
  67. compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'
  68.  
  69. }
Add Comment
Please, Sign In to add comment