Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. @Entity
  2. @Table(name = "user", schema = "public")
  3. public class User extends BaseEntity{
  4. private Integer id;
  5. private String name;
  6. private Integer contractId;
  7.  
  8. public User() {
  9. }
  10.  
  11. public User(Integer id) {
  12. super(id);
  13. }
  14.  
  15. @Id
  16. @Column(name = "usr_id", nullable = false)
  17. @GeneratedValue(strategy= GenerationType.IDENTITY)
  18. public Integer getId() {
  19. return id;
  20. }
  21.  
  22. public void setId(Integer id) {
  23. this.id = id;
  24. }
  25.  
  26. @Basic
  27. @Column(name = "usr_name", nullable = true, length = -1)
  28. public String getName() {
  29. return name;
  30. }
  31.  
  32. public void setName(String name) {
  33. this.name = name;
  34. }
  35.  
  36. @Basic
  37. @Column(name = "usr_contract_id", nullable = true)
  38. public Integer getContractId() {
  39. return contractId;
  40. }
  41.  
  42. public void setContractId(Integer contractId) {
  43. this.contractId = contractId;
  44. }
  45.  
  46. }
  47.  
  48. @Configuration
  49. @EnableTransactionManagement(proxyTargetClass = true)
  50. @PropertySources({
  51. @PropertySource(value = "classpath:application.properties")})
  52. @ConfigurationProperties(prefix = "spring.datasource")
  53. public class HibernateConfig {
  54.  
  55. @Autowired
  56. private Environment environment;
  57.  
  58. @Autowired
  59. private DataSource dataSource;
  60.  
  61. @Autowired
  62. private MultiTenantConnectionProvider multiTenantConnectionProvider;
  63.  
  64. @Autowired
  65. private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
  66.  
  67. public HibernateConfig() {
  68.  
  69. }
  70.  
  71. @Bean
  72. public LocalSessionFactoryBean sessionFactory() throws Exception {
  73.  
  74. LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
  75. sessionFactory.setDataSource(dataSource);
  76. sessionFactory.setHibernateProperties(hibernateProperties());
  77.  
  78. sessionFactory.setPackagesToScan(new String[] {
  79. "com.xxx.xxx.model",
  80. });
  81.  
  82. return sessionFactory;
  83. }
  84.  
  85. private Properties hibernateProperties() {
  86. Properties properties = new Properties();
  87. properties.put(DIALECT, environment.getRequiredProperty(DIALECT));
  88. properties.put(SHOW_SQL, environment.getRequiredProperty(SHOW_SQL));
  89. properties.put(FORMAT_SQL, environment.getRequiredProperty(FORMAT_SQL));
  90. properties.put(HBM2DDL_AUTO, environment.getRequiredProperty(HBM2DDL_AUTO));
  91.  
  92. return properties;
  93. }
  94.  
  95. @Bean
  96. @Primary
  97. @Autowired
  98. public HibernateTransactionManager transactionManager(SessionFactory s) {
  99. HibernateTransactionManager txManager = new HibernateTransactionManager();
  100. txManager.setSessionFactory(s);
  101. return txManager;
  102. }
  103.  
  104. @Bean
  105. @Autowired
  106. public HibernateTemplate hibernateTemplate(SessionFactory s) {
  107. HibernateTemplate hibernateTemplate = new HibernateTemplate(s);
  108. return hibernateTemplate;
  109. }
  110. }
  111.  
  112. # Database connection settings:
  113. jdbc.driverClassName=org.postgresql.Driver
  114. jdbc.url=jdbc:postgresql://localhost:5432/database
  115. jdbc.username=postgres
  116. jdbc.password=111111
  117.  
  118. hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  119. hibernate.show_sql=false
  120. hibernate.format_sql=false
  121. hibernate.hbm2ddl.auto=update
  122.  
  123. spring.datasource.initialSize=50
  124. spring.datasource.maxActive=200
  125. spring.datasource.maxIdle=200
  126. spring.datasource.minIdle=50
  127.  
  128. spring.jpa.hibernate.ddl-auto=update
  129. spring.jpa.generate-ddl=true
  130. spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL94Dialect
  131.  
  132. spring.datasource.driverClassName=org.postgresql.Driver
  133. spring.datasource.url= jdbc:postgresql://localhost:5432/postgres
  134. spring.datasource.username=postgres
  135. spring.datasource.password=123
  136.  
  137. spring.jpa.show-sql=true
  138. spring.session.store-type=none
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement