Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.96 KB | None | 0 0
  1. // Role model
  2.  
  3. @Entity
  4. @Table(name = "role")
  5. class Role {
  6.  
  7. @Id
  8. @Column(name = "id", unique = true)
  9. @GeneratedValue(strategy = GenerationType.IDENTITY)
  10. open var id: Long? = null
  11.  
  12. @Column(name = "name", nullable = false)
  13. lateinit var name: String
  14. }
  15.  
  16. // Application
  17.  
  18. interface RoleRepository: CrudRepository<Role, Long>
  19.  
  20. @SpringBootApplication
  21. open class Application {
  22. @Autowired
  23. lateinit var roleRepository: RoleRepository
  24.  
  25. @Bean
  26. open fun demo(): CommandLineRunner = CommandLineRunner {
  27. createRole(roleRepository)
  28. print("Roles count: " + roleRepository.count() + "\n")
  29. }
  30. }
  31.  
  32. fun main(args: Array<String>) {
  33. SpringApplication.run(Application::class.java, *args)
  34. }
  35.  
  36. fun createRole(roleRepository: RoleRepository) {
  37. val r = Role()
  38. r.name = "test"
  39.  
  40. roleRepository.save(r)
  41. }
  42.  
  43. // Bean Config
  44.  
  45. @Configuration
  46. @EnableTransactionManagement
  47. open class BeanConfig {
  48.  
  49. @Autowired
  50. lateinit open var entityManagerFactory: EntityManagerFactory
  51.  
  52. @Bean
  53. open fun getSessionFactory() = entityManagerFactory.unwrap(SessionFactory::class.java)
  54. ?: throw NullPointerException("factory is not a hibernate factory")
  55.  
  56. @Bean
  57. @Autowired
  58. open fun transactionManager(sessionFactory: SessionFactory) = HibernateTransactionManager(sessionFactory)
  59.  
  60. }
  61.  
  62.  
  63. // Output
  64.  
  65. :: Spring Boot :: (v1.5.6.RELEASE)
  66.  
  67. 2017-08-15 16:32:58.834 INFO 96888 --- [ main] r.t.spring.jpa.versioning.ApplicationKt : Starting ApplicationKt on MBP-Ivan with PID 96888 (/Users/ivansmolin/Projects/spring-jpa-versioning/out/production/classes started by ivansmolin in /Users/ivansmolin/Projects/spring-jpa-versioning)
  68. 2017-08-15 16:32:58.839 INFO 96888 --- [ main] r.t.spring.jpa.versioning.ApplicationKt : No active profile set, falling back to default profiles: default
  69. 2017-08-15 16:32:58.927 INFO 96888 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@38364841: startup date [Tue Aug 15 16:32:58 MSK 2017]; root of context hierarchy
  70. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  71. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  72. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  73. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  74. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  75. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  76. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  77. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  78. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  79. Tue Aug 15 16:33:00 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  80. 2017-08-15 16:33:00.530 INFO 96888 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
  81. 2017-08-15 16:33:00.547 INFO 96888 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
  82. name: default
  83. ...]
  84. 2017-08-15 16:33:00.608 INFO 96888 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
  85. 2017-08-15 16:33:00.609 INFO 96888 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
  86. 2017-08-15 16:33:00.610 INFO 96888 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
  87. 2017-08-15 16:33:00.664 INFO 96888 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  88. 2017-08-15 16:33:00.786 INFO 96888 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57InnoDBDialect
  89. 2017-08-15 16:33:01.190 INFO 96888 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
  90. 2017-08-15 16:33:01.198 DEBUG 96888 --- [ main] org.hibernate.SQL : drop table if exists role
  91. Hibernate: drop table if exists role
  92. 2017-08-15 16:33:01.205 DEBUG 96888 --- [ main] org.hibernate.SQL : create table role (id bigint not null auto_increment, name varchar(255) not null, primary key (id)) ENGINE=InnoDB
  93. Hibernate: create table role (id bigint not null auto_increment, name varchar(255) not null, primary key (id)) ENGINE=InnoDB
  94. 2017-08-15 16:33:01.230 INFO 96888 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
  95. 2017-08-15 16:33:01.265 INFO 96888 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  96. 2017-08-15 16:33:01.504 INFO 96888 --- [ main] o.s.o.h.HibernateTransactionManager : Using DataSource [org.apache.tomcat.jdbc.pool.DataSource@517566b{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=com.mysql.cj.jdbc.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:mysql://localhost:3306/test_calc?serverTimezone=UTC; username=root; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; useStatementFacade=true; }] of Hibernate SessionFactory for HibernateTransactionManager
  97. 2017-08-15 16:33:01.699 INFO 96888 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
  98. 2017-08-15 16:33:01.768 INFO 96888 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
  99. 2017-08-15 16:33:01.977 DEBUG 96888 --- [ main] org.hibernate.SQL : select count(*) as col_0_0_ from role role0_
  100. Hibernate: select count(*) as col_0_0_ from role role0_
  101. Roles count: 0
  102. 2017-08-15 16:33:02.032 INFO 96888 --- [ main] r.t.spring.jpa.versioning.ApplicationKt : Started ApplicationKt in 3.573 seconds (JVM running for 3.999)
  103. 2017-08-15 16:33:02.033 INFO 96888 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@38364841: startup date [Tue Aug 15 16:32:58 MSK 2017]; root of context hierarchy
  104. 2017-08-15 16:33:02.035 INFO 96888 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
  105. 2017-08-15 16:33:02.037 INFO 96888 --- [ Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  106. 2017-08-15 16:33:02.038 WARN 96888 --- [ Thread-3] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'entityManagerFactory': java.lang.IllegalStateException: EntityManagerFactory is closed
  107.  
  108. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement