How to create an H2+flyway test database in spring boot? - spring-boot

I have a spring boot project where I want to test my controller.I use MySql database for production but want an in memory database for running the testcases.I use Flyway for versioning database migration.I want my test database to use the same versioning.Can someone please help me with a way to do that?
This is what my application.properties in src/test/resources folder looks like:
# Database Properties
spring.jpa.database=H2
spring.database.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;INIT=CREATE SCHEMA IF NOT EXISTS public;DATABASE_TO_UPPER=false
spring.h2.console.enabled=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
security.basic.enabled:false
spring.datasource.username:sa
spring.datasource.password:
# Flyway Properties
spring.flyway.locations=filesystem:src/main/resources/db/migration
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
This is my Test File:
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
#SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
#AutoConfigureMockMvc
#ContextConfiguration
public class PermissionsControllerTest {
#Autowired
private MockMvc mockMvc;
#Test
public void existentUserCanGetTokenAndAuthenticationAndAlsoExtractPermissions() throws Exception {
String username = "Srishti";
String body = "{" + "\"username\":\"" + username + "\"}";
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/authenticate")
.contentType(MediaType.APPLICATION_JSON_VALUE).content(body)).andDo(print()).andExpect(status().isOk())
.andReturn();
String response = result.getResponse().getContentAsString();
mockMvc.perform(MockMvcRequestBuilders.get("/permission").header("Authorization", "Bearer " + response))
.andExpect(status().isOk()).andDo(print()).andReturn();
mockMvc.perform(MockMvcRequestBuilders.get("/permission/9").header("Authorization", "Bearer " + response))
.andExpect(status().isOk()).andDo(print()).andReturn();
}
}
And this is the output that I get currently get:
2020-09-06 19:30:54.481 INFO 26936 --- [ main] c.t.L.PermissionsControllerTest : Starting PermissionsControllerTest on DGKDSQ13 with PID 26936 (started by SrishtiChawla in C:\Users\srishtichawla\Desktop\LCTraining\LCTraining)
2020-09-06 19:30:54.483 INFO 26936 --- [ main] c.t.L.PermissionsControllerTest : No active profile set, falling back to default profiles: default
2020-09-06 19:30:55.599 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-09-06 19:30:55.600 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2020-09-06 19:30:55.670 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.LOBRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.672 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.PermissionsRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.674 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.ProductCategoryRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.677 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.RolesRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.679 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.ScoringModelSuiteRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.681 INFO 26936 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.training.LCtraining.repository.UserRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-09-06 19:30:55.682 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 74ms. Found 0 JDBC repository interfaces.
2020-09-06 19:30:55.694 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-09-06 19:30:55.695 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-09-06 19:30:55.762 INFO 26936 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 63ms. Found 6 JPA repository interfaces.
2020-09-06 19:30:56.308 INFO 26936 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#1e5eb20a' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-06 19:30:56.325 INFO 26936 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-06 19:30:57.018 INFO 26936 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 0 (http)
2020-09-06 19:30:57.032 INFO 26936 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-06 19:30:57.033 INFO 26936 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-09-06 19:30:57.216 INFO 26936 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-06 19:30:57.216 INFO 26936 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2708 ms
2020-09-06 19:30:57.353 WARN 26936 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-09-06 19:30:57.509 INFO 26936 --- [ main] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 6.4.4 by Redgate
2020-09-06 19:30:57.515 INFO 26936 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-09-06 19:30:57.746 INFO 26936 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-09-06 19:30:57.773 INFO 26936 --- [ main] o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
2020-09-06 19:30:57.864 INFO 26936 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 9 migrations (execution time 00:00.036s)
2020-09-06 19:30:57.883 INFO 26936 --- [ main] o.f.c.i.s.JdbcTableSchemaHistory : Creating Schema History table "PUBLIC"."flyway_schema_history" ...
2020-09-06 19:30:57.955 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >>
2020-09-06 19:30:57.970 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.1 - createTables
2020-09-06 19:30:58.100 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.2 - inservalues
2020-09-06 19:30:58.144 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.3 - altertable
2020-09-06 19:30:58.183 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.4 - INSERTVALUES2
2020-09-06 19:30:58.216 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.5 - insertvalues3
2020-09-06 19:30:58.241 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.6 - ALTERTABLE
2020-09-06 19:30:58.264 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.7 - Altertablelob
2020-09-06 19:30:58.293 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.8 - insertvals
2020-09-06 19:30:58.315 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 1.10 - uniquekey
2020-09-06 19:30:58.330 INFO 26936 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 9 migrations to schema "PUBLIC" (execution time 00:00.383s)
2020-09-06 19:30:58.541 INFO 26936 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-06 19:30:58.639 INFO 26936 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-06 19:30:58.711 INFO 26936 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.18.Final
2020-09-06 19:30:58.903 INFO 26936 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-09-06 19:30:59.060 INFO 26936 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-09-06 19:30:59.320 INFO 26936 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
2020-09-06 19:30:59.970 INFO 26936 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-09-06 19:30:59.982 INFO 26936 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-09-06 19:31:00.409 INFO 26936 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-09-06 19:31:00.489 INFO 26936 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#1c43e84e, org.springframework.security.web.context.SecurityContextPersistenceFilter#5e62ca19, org.springframework.security.web.header.HeaderWriterFilter#493968a9, org.springframework.web.filter.CorsFilter#7bd694a5, org.springframework.security.web.authentication.logout.LogoutFilter#322ab6ce, com.training.LCtraining.filter.JwtFilter#af9dd34, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#6528d339, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#3149409c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#21ce2e4d, org.springframework.security.web.session.SessionManagementFilter#780c0, org.springframework.security.web.access.ExceptionTranslationFilter#7a8b7e11, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#11ee671f]
2020-09-06 19:31:01.178 INFO 26936 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring TestDispatcherServlet ''
2020-09-06 19:31:01.179 INFO 26936 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Initializing Servlet ''
2020-09-06 19:31:01.195 INFO 26936 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Completed initialization in 16 ms
2020-09-06 19:31:01.298 INFO 26936 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 51516 (http) with context path ''
2020-09-06 19:31:01.300 INFO 26936 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-09-06 19:31:01.785 INFO 26936 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-09-06 19:31:01.801 INFO 26936 --- [ main] c.t.L.PermissionsControllerTest : Started PermissionsControllerTest in 7.711 seconds (JVM running for 9.214)
Hibernate: select user0_.user_id as user_id1_9_, user0_.lob_id as lob_id4_9_, user0_.enabled as enabled2_9_, user0_.role_id as role_id5_9_, user0_.username as username3_9_ from user user0_ where user0_.username=?
2020-09-06 19:31:02.278 WARN 26936 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 42102, SQLState: 42S02
2020-09-06 19:31:02.279 ERROR 26936 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Table "user" not found; SQL statement:
select user0_.user_id as user_id1_9_, user0_.lob_id as lob_id4_9_, user0_.enabled as enabled2_9_, user0_.role_id as role_id5_9_, user0_.username as username3_9_ from user user0_ where user0_.username=? [42102-200]
MockHttpServletRequest:
HTTP Method = POST
Request URI = /authenticate
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Content-Length:"22"]
Body = {"username":"Srishti"}
Session Attrs = {}
Handler:
Type = com.training.LCtraining.integration.UserRestController
Method = com.training.LCtraining.integration.UserRestController#generateToken(AuthRequest)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = org.springframework.dao.InvalidDataAccessResourceUsageException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 401
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", Content-Type:"application/json", X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
Content type = application/json
Body = {"timestamp":"2020-09-06","message":"could not prepare statement; SQL [select user0_.user_id as user_id1_9_, user0_.lob_id as lob_id4_9_, user0_.enabled as enabled2_9_, user0_.role_id as role_id5_9_, user0_.username as username3_9_ from user user0_ where user0_.username=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement","details":"uri=/authenticate"}
Forwarded URL = null
Redirected URL = null
Cookies = []
MockHttpServletRequest:
HTTP Method = POST
Request URI = /authenticate
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Content-Length:"22"]
Body = {"username":"Srishti"}
Session Attrs = {}
Handler:
Type = com.training.training.integration.UserRestController
Method = com.training.training.integration.UserRestController#generateToken(AuthRequest)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = org.springframework.dao.InvalidDataAccessResourceUsageException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 401
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", Content-Type:"application/json", X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
Content type = application/json
Body = {"timestamp":"2020-09-06","message":"could not prepare statement; SQL [select user0_.user_id as user_id1_9_, user0_.lob_id as lob_id4_9_, user0_.enabled as enabled2_9_, user0_.role_id as role_id5_9_, user0_.username as username3_9_ from user user0_ where user0_.username=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement","details":"uri=/authenticate"}
Forwarded URL = null
Redirected URL = null
Cookies = []
2020-09-06 19:31:02.656 INFO 26936 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-09-06 19:31:02.659 INFO 26936 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-09-06 19:31:02.659 INFO 26936 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-09-06 19:31:02.664 INFO 26936 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
The controllers are working fine on the production side.
This is my V1.1__createtable.sql file
create table permissions(
permissionID int not null auto_increment,
permissionTitle varchar(40) not null,
permissionDescription varchar(255),
PRIMARY KEY (permissionID),
UNIQUE (permissionTitle));
insert into permissions(permissionTitle) values('Create Role');
insert into permissions(permissionTitle) values('Edit Role');
insert into permissions(permissionTitle) values('Delete Role');
insert into permissions(permissionTitle) values('Create User');
insert into permissions(permissionTitle) values('Edit User');
insert into permissions(permissionTitle) values('Delete User');
insert into permissions(permissionTitle) values('Create LOB');
insert into permissions(permissionTitle) values('Edit LOB');
insert into permissions(permissionTitle) values('Delete LOB');

According to the logs, Flyway is executed successfully:
Flyway Community Edition 6.4.4 by Redgate
HikariPool-1 - Starting...
HikariPool-1 - Start completed.
Database: jdbc:h2:mem:testdb (H2 1.4)
Successfully validated 9 migrations (execution time 00:00.036s)
Creating Schema History table "PUBLIC"."flyway_schema_history" ...
Current version of schema "PUBLIC": << Empty Schema >>
Migrating schema "PUBLIC" to version 1.1 - createTables
Migrating schema "PUBLIC" to version 1.2 - inservalues
Migrating schema "PUBLIC" to version 1.3 - altertable
Migrating schema "PUBLIC" to version 1.4 - INSERTVALUES2
Migrating schema "PUBLIC" to version 1.5 - insertvalues3
Migrating schema "PUBLIC" to version 1.6 - ALTERTABLE
Migrating schema "PUBLIC" to version 1.7 - Altertablelob
Migrating schema "PUBLIC" to version 1.8 - insertvals
Migrating schema "PUBLIC" to version 1.10 - uniquekey
Successfully applied 9 migrations to schema "PUBLIC" (execution time 00:00.383s)
You can see that 9 migrations are applied: createTables, inservalues, altertable, INSERTVALUES2, insertvalues3, ALTERTABLE, Altertablelob, insertvals, uniquekey.
Is this list complete or are you expecting more migrations?
The error you see later in the log comes from Hibernate, not from Flyway.
And it says:
Table "user" not found
Looking the migration names, I would expect that the user table is created by the createTables migration. But there's no CREATE TABLE 'user' statement in V1.1__createTables.sql.
Please double-check that all necessary tables are defined in your migrations. You should NOT alter old migrations. Instead, you can create new migrations for the missing tables and use CREATE TABLE IF NOT EXISTS syntax, so that it's compatible with existing production environment.

I had a similar problem and my solution was described in a comment by #Srish. Changing my url from jdbc:h2:mem:[MYDB] to jdbc:h2:file:~/[MYDB] allowed flyway to successfully perform the migrations as well perform JPA's validation.

Related

SpringBoot does not detect template of Thymeleaf

I started learning Thymeleaf templating with SpringBoot and my learning path was blocked by some implicit issue i could not find....
The issue is: SpringBoot app does not see template, although:
Controller looks like
Project structure includes /templates:
All required dependencies are in place:
Spring Boot log:
2022-11-13 22:21:13.196 INFO 20644 --- [ main]
com.coffeeshop.Application : Starting Application using
Java 11.0.10 on LAPTOP-O6B9USVI with PID 20644
(C:\Dev\Java\Projects\coffeeshop\build\classes\java\main started by
User in C:\Dev\Java\Projects\coffeeshop) 2022-11-13 22:21:13.196 INFO
20644 --- [ main] com.coffeeshop.Application :
No active profile set, falling back to 1 default profile: "default"
2022-11-13 22:21:13.588 INFO 20644 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
JPA repositories in DEFAULT mode. 2022-11-13 22:21:13.604 INFO 20644
--- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23 ms. Found 1 JPA
repository interfaces. 2022-11-13 22:21:14.106 INFO 20644 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized
with port(s): 8081 (http) 2022-11-13 22:21:14.106 INFO 20644 --- [
main] o.apache.catalina.core.StandardService : Starting service
[Tomcat] 2022-11-13 22:21:14.106 INFO 20644 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/9.0.64] 2022-11-13 22:21:14.184 INFO 20644 --- [
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring
embedded WebApplicationContext 2022-11-13 22:21:14.184 INFO 20644 ---
[ main] w.s.c.ServletWebServerApplicationContext : Root
WebApplicationContext: initialization completed in 957 ms 2022-11-13
22:21:14.278 INFO 20644 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default] 2022-11-13 22:21:14.309 INFO
20644 --- [ main] org.hibernate.Version :
HHH000412: Hibernate ORM core version 5.6.9.Final 2022-11-13
22:21:14.309 INFO 20644 --- [ main]
org.hibernate.cfg.Environment : HHH000205: Loaded
properties from resource hibernate.properties:
{hibernate.temp.use_jdbc_metadata_defaults=false,
hibernate.bytecode.use_reflection_optimizer=false} 2022-11-13
22:21:14.404 INFO 20644 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.1.2.Final} 2022-11-13 22:21:14.466 INFO 20644
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-11-13 22:21:14.796 INFO 20644 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-11-13 22:21:14.905 INFO 20644 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed. 2022-11-13 22:21:14.921 INFO 20644 --- [ main]
o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using
JtaPlatform implementation:
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-11-13 22:21:14.921 INFO 20644 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default' 2022-11-13
22:21:15.094 WARN 20644 --- [ main]
JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is
enabled by default. Therefore, database queries may be performed
during view rendering. Explicitly configure spring.jpa.open-in-view to
disable this warning 2022-11-13 22:21:15.298 INFO 20644 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on
port(s): 8081 (http) with context path '' 2022-11-13 22:21:15.298
INFO 20644 --- [ main] com.coffeeshop.Application
: Started Application in 2.409 seconds (JVM running for 2.7)
When i check http://localhost:8081/home I got "home" string only.
Replace #RestController with #Controller. You cannot use #RestController because #RestController automatically adds #ResponseBody and Spring will only attempt to look up a view if #ResponseBody is not present.
This should fix your problem
#Controller
public class AppController {
#GetMapping("/")
public String viewHomePage() {
return "home";
}
}

JPA ColumnTransformer write is not working

this is my entity.
#Getter
#Setter
#Entity
#Table(name = "crypt_test_table")
#IdClass(value = SqlFunctionTest.class) public class SqlFunctionTest implements Serializable {
#Id
private Long id;
#Column(name = "name")
#ColumnTransformer(
forColumn = "name",
read = "CONVERT(AES_DECRYPT(name, get_enc_key() ,get_aes_init_vector()) USING utf8)",
write = "AES_ENCRYPT(?, get_enc_key(), get_aes_init_vector())"
)
private String name;
}
I m trying to insert and select by encrypt and decrypt which I declared on my entity.
when I read it, it worked. like this.
SELECT
SQLFUNCTIO0_.ID AS ID1_13_,
SQLFUNCTIO0_.NAME AS NAME2_13_
FROM
CRYPT_TEST_TABLE SQLFUNCTIO0_
WHERE
CONVERT(AES_DECRYPT(SQLFUNCTIO0_.NAME, GET_ENC_KEY() ,GET_AES_INIT_VECTOR()) USING UTF8)='TROY.T'
but when i save an entity, it doesn't work like this.
INSERT
INTO
CRYPT_TEST_TABLE
(ID, NAME)
VALUES
(NULL, 'TROY.T')
This is the test code I did.
#Test
public void testSave(){
System.out.println("JPA TEST");
SqlFunctionTest entity = new SqlFunctionTest();
entity.setName("troy.t");
jpaCryptoService.save(entity);
}
#Test
public void testSelect(){
List<SqlFunctionTest> op = jpaCryptoService.findByName("troy.t");
System.out.println("op = " + op);
}
What's wrong with me?
2022-07-11T10:27:02.091+09:00 INFO 25748 --- [kground-preinit] o.h.v.i.u.Version : HV000001: Hibernate Validator 6.2.3.Final
2022-07-11T10:27:02.126+09:00 INFO 25748 --- [ main] ApplicationTest : Starting ApplicationTest using Java 11.0.14.1 on TroyTui-MacBookPro.local with PID 25748
2022-07-11T10:27:03.188+09:00 INFO 25748 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-07-11T10:27:03.592+09:00 INFO 25748 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 399 ms. Found 122 JPA repository interfaces.
2022-07-11T10:27:04.501+09:00 INFO 25748 --- [ main] c.z.h.HikariDataSource : HikariPool-1 - Starting...
2022-07-11T10:27:04.751+09:00 INFO 25748 --- [ main] c.z.h.HikariDataSource : HikariPool-1 - Start completed.
2022-07-11T10:27:04.829+09:00 INFO 25748 --- [ main] o.h.j.i.u.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-07-11T10:27:04.867+09:00 INFO 25748 --- [ main] o.h.Version : HHH000412: Hibernate ORM core version 5.6.9.Final
2022-07-11T10:27:04.996+09:00 INFO 25748 --- [ main] o.h.a.c.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-07-11T10:27:05.073+09:00 INFO 25748 --- [ main] o.h.d.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2022-07-11T10:27:05.564+09:00 WARN 25748 --- [ main] o.h.m.RootClass : HHH000038: Composite-id class does not override equals(): com.dktechin.saas.smartfactory.test.SqlFunctionTest
2022-07-11T10:27:05.564+09:00 WARN 25748 --- [ main] o.h.m.RootClass : HHH000039: Composite-id class does not override hashCode(): com.dktechin.saas.smartfactory.test.SqlFunctionTest
2022-07-11T10:27:06.228+09:00 INFO 25748 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-07-11T10:27:06.233+09:00 INFO 25748 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-07-11T10:27:10.167+09:00 INFO 25748 --- [ main] o.e.j.u.log : Logging initialized #9863ms to org.eclipse.jetty.util.log.Slf4jLog
2022-07-11T10:27:11.211+09:00 INFO 25748 --- [ main] ApplicationTest : Started ApplicationTest in 9.59 seconds (JVM running for 10.908)
JPA TEST
2022-07-11T10:27:11.393+09:00 INFO 25748 --- [ main] p6spy :
SELECT
SQLFUNCTIO0_.ID AS ID1_13_0_,
SQLFUNCTIO0_.NAME AS NAME2_13_0_
FROM
CRYPT_TEST_TABLE SQLFUNCTIO0_
WHERE
SQLFUNCTIO0_.ID=NULL
AND SQLFUNCTIO0_.NAME='TROY.T'
Connection ID: 2
Execution Time: 24 ms
Call Stack (number 1 is entry point):
----------------------------------------------------------------------------------------------------
2022-07-11T10:27:11.443+09:00 INFO 25748 --- [ main] p6spy :
INSERT
INTO
CRYPT_TEST_TABLE
(ID, NAME)
VALUES
(NULL, 'TROY.T')
Connection ID: 2
Execution Time: 14 ms
Call Stack (number 1 is entry point):
----------------------------------------------------------------------------------------------------
2022-07-11T10:27:11.602+09:00 INFO 25748 --- [ main] p6spy :
SELECT
SQLFUNCTIO0_.ID AS ID1_13_,
SQLFUNCTIO0_.NAME AS NAME2_13_
FROM
CRYPT_TEST_TABLE SQLFUNCTIO0_
WHERE
CONVERT(AES_DECRYPT(SQLFUNCTIO0_.NAME, GET_ENC_KEY() ,GET_AES_INIT_VECTOR()) USING UTF8)='TROY.T'
Connection ID: 3
Execution Time: 14 ms
Call Stack (number 1 is entry point):
----------------------------------------------------------------------------------------------------
op = []

Not Able to fetch table in Oracle Database after creating a table using JPA hibernate

I am trying to connect Oracle Database 12c using spring boot, and creating a table using JPA hibernate and code is running fine also in postman get and post working fine(request is hitting and tables are created). now when I am chekcing tables in my oracle database 12c I am getting output as table does not exist.
here is my database connection file
## Database Properties
#spring.datasource.url = jdbc:mysql://localhost:3306/detail?useSSL=false
spring.datasource.url= jdbc:oracle:thin:#<IP>:1521/<pdb database service name>
spring.datasource.username=sys as sysdba
spring.datasource.password=Welcome1
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
server.port=8081
spring.jpa.show-sql=true
This is my Output after executing the code
2020-01-31 16:06:40.916 WARN 7724 --- [ restartedMain] o.s.boot.StartupInfoLogger : InetAddress.getLocalHost().getHostName() took 5006 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).
2020-01-31 16:06:45.927 INFO 7724 --- [ restartedMain] com.example.DemoApplication : Starting DemoApplication on Kirtis-Mac.local with PID 7724 (/Users/kirtijain/Downloads/demo/target/classes started by kirtijain in /Users/kirtijain/Downloads/demo)
2020-01-31 16:06:45.927 INFO 7724 --- [ restartedMain] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2020-01-31 16:06:46.341 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-01-31 16:06:46.342 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2020-01-31 16:06:46.351 INFO 7724 --- [ restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.example.repository.UserRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
2020-01-31 16:06:46.351 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 JDBC repository interfaces.
2020-01-31 16:06:46.358 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-01-31 16:06:46.359 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-01-31 16:06:46.365 INFO 7724 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6ms. Found 1 JPA repository interfaces.
2020-01-31 16:06:46.506 INFO 7724 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$9bd21857] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-31 16:06:46.511 INFO 7724 --- [ restartedMain] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2020-01-31 16:06:46.523 INFO 7724 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-31 16:06:47.870 INFO 7724 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2020-01-31 16:06:47.872 INFO 7724 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-31 16:06:47.873 INFO 7724 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-01-31 16:06:47.950 INFO 7724 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-31 16:06:47.950 INFO 7724 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2016 ms
2020-01-31 16:06:48.059 INFO 7724 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-01-31 16:06:48.076 INFO 7724 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Starting...
2020-01-31 16:06:48.077 WARN 7724 --- [ restartedMain] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
2020-01-31 16:06:53.326 INFO 7724 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Start completed.
2020-01-31 16:06:53.326 INFO 7724 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
Hibernate: create table test_table (id number(19,0) generated as identity, created_by varchar2(50 char) not null, created_date timestamp, email_address varchar2(255 char) not null, first_name varchar2(255 char) not null, last_modified_by varchar2(50 char), last_modified_date timestamp, last_name varchar2(255 char) not null, primary key (id))
2020-01-31 16:07:02.689 INFO 7724 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-01-31 16:07:02.690 INFO 7724 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-01-31 16:07:02.699 INFO 7724 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-01-31 16:07:02.876 WARN 7724 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-01-31 16:07:02.956 INFO 7724 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-01-31 16:07:03.142 INFO 7724 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2020-01-31 16:07:03.142 INFO 7724 --- [ restartedMain] com.example.DemoApplication : Started DemoApplication in 32.29 seconds (JVM running for 753.748)
2020-01-31 16:07:03.144 INFO 7724 --- [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
spring started
Result in Oracle Database
the tables are there so you probably connect to the wrong schema. You can see the schema where you are with
show user
You can find out where the table is querying the data dictionary with
select table_name, owner from all_tables where table_name = 'test_table';
One advice: it is a bad practise to connect as sys as sysdba from the application.
You should create a new schema (i.e. TEST) and connect with those credentials: aside the security aspects (your application cannot change everything in the database) you create by default tables (and any other object) in the designated Oracle schema.

Spring Boot Run failed

I am using Spring to build my application.
I used Spring Initializr to build my project.
I included the following dependencies:-
JPA
h2 (database)
ThymeLeaf templating engine
Spring Actuator
DevTools
Security
I am using IntelliJ IDEA IDE using Gradle build on Windows Machine.
NOTE:- I have not changed gradle(v4.8) build file.
Down below is the result of running SpringBootApplication:-
"C:\Program Files\Java\jdk1.8.0_171\bin\java.exe" -javaagent:C:\Users\ayman\Downloads\Software\IntelliJIdea\lib\idea_rt.jar=61199:C:\Users\E080978\Downloads\Software\IntelliJIdea\bin -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;C:\Users\E080978\Downloads\Mastercard Image\demo\out\production\classes;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-actuator\2.0.3.RELEASE\d370eeff676d24523ee530f6abc569474d2f9bf9\spring-boot-starter-actuator-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-jpa\2.0.3.RELEASE\56c909f49b5385793942158e143187ecc8c7b54a\spring-boot-starter-data-jpa-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-security\2.0.3.RELEASE\67de3ced1ebc68c7bbd9bc2ced390821fa682c2f\spring-boot-starter-security-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-thymeleaf\2.0.3.RELEASE\7a8cf11f5b7faa244e1979df491811bc0c858743\spring-boot-starter-thymeleaf-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-aop\2.0.3.RELEASE\a78c7bc25fd51b217f078421dc40d13ddc3b9f8f\spring-boot-starter-aop-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-jdbc\2.0.3.RELEASE\4f5f3411692a0f5efb60f7f583bdfcf49199a3d4\spring-boot-starter-jdbc-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.0.3.RELEASE\ffaa050dbd36b0441645598f1a7ddaf67fd5e678\spring-boot-starter-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-devtools\2.0.3.RELEASE\478e12e423b45d182a409f12a28fb9f0cddf84bf\spring-boot-devtools-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-actuator-autoconfigure\2.0.3.RELEASE\f3e3392c3e8e2714fc05bbf0f3ee496ad19eedc7\spring-boot-actuator-autoconfigure-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.h2database\h2\1.4.197\bb391050048ca8ae3e32451b5a3714ecd3596a46\h2-1.4.197.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\io.micrometer\micrometer-core\1.0.5\c5eaa23f5bb1f0f4b7eb44824093874d0d9165f5\micrometer-core-1.0.5.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.hibernate\hibernate-core\5.2.17.Final\f2dc36470e7a2ffcf6106bb1625ecf5b54bb5f65\hibernate-core-5.2.17.Final.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\javax.transaction\javax.transaction-api\1.2\d81aff979d603edd90dcd8db2abc1f4ce6479e3e\javax.transaction-api-1.2.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-jpa\2.0.8.RELEASE\8b874afd15da2b4d2d9b8431ad2be0c6829e41fe\spring-data-jpa-2.0.8.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aspects\5.0.7.RELEASE\afd3f7ecb9d7c2cb3160563f9f64b72223bb0265\spring-aspects-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-config\5.0.6.RELEASE\60367d94d253c82781b7f9abf2294cd0295e1c1\spring-security-config-5.0.6.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-web\5.0.6.RELEASE\f502d929ee62f5dce0fc942f5a22faa52eaaac34\spring-security-web-5.0.6.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.0.3.RELEASE\11bc4cc96b08fabad2b3186755818fa0b32d83f\spring-boot-autoconfigure-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-actuator\2.0.3.RELEASE\5aa239d8ad6d8130b055caebf44467b9c55d422b\spring-boot-actuator-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.0.3.RELEASE\b874870d915adbc3dd932e19077d3d45c8e54aa0\spring-boot-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-core\5.0.6.RELEASE\11c0291cc9cda839b7feb52c519f4a35dc6e251b\spring-security-core-5.0.6.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.0.7.RELEASE\243a23f8968de8754d8199d669780d683ab177bd\spring-context-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.0.7.RELEASE\fdd0b6aa3c9c7a188c3bfbf6dfd8d40e843be9ef\spring-aop-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf-spring5\3.0.9.RELEASE\abf84efd83808a70d982d2790f7f3a7bd3a39cf4\thymeleaf-spring5-3.0.9.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.thymeleaf.extras\thymeleaf-extras-java8time\3.0.1.RELEASE\d23760d1e53cd70c489ef40dc94ee6bd2371cceb\thymeleaf-extras-java8time-3.0.1.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.0.3.RELEASE\7caad34f01d2688919e15e09a90467963e3d5190\spring-boot-starter-logging-2.0.3.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-orm\5.0.7.RELEASE\4deed5f4a38d62f9dba7db8e010da8b49e322757\spring-orm-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jdbc\5.0.7.RELEASE\9c78c6b9a6c603f6589b480e165939cde7bab7f9\spring-jdbc-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\2.0.8.RELEASE\5c19af63b5acb0eab39066684e813d5ecd9d03b7\spring-data-commons-2.0.8.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-tx\5.0.7.RELEASE\4ca59b21c61162adb146ad1b40c30b60d8dc42b8\spring-tx-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.0.7.RELEASE\2e04c6c2922fbfa06b5948be14a5782db168b6ec\spring-web-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.0.7.RELEASE\c1196cb3e56da83e3c3a02ef323699f4b05feedc\spring-beans-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.0.7.RELEASE\ca01fb473f53dd0ee3c85663b26d5dc325602057\spring-expression-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.0.7.RELEASE\54b731178d81e66eca9623df772ff32718208137\spring-core-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.19\2d998d3d674b172a588e54ab619854d073f555b5\snakeyaml-1.19.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.9.6\ea54f6193d224e5e5732bbd4262327eb465397c2\jackson-datatype-jsr310-2.9.6.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.9.6\cfa4f316351a91bfd95cb0644c6a2c95f52db1fc\jackson-databind-2.9.6.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.hdrhistogram\HdrHistogram\2.1.10\9e1ac84eed220281841b75e72fb9de5a297fbf04\HdrHistogram-2.1.10.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.latencyutils\LatencyUtils\2.0.3\769c0b82cb2421c8256300e907298a9410a2a3d3\LatencyUtils-2.0.3.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.aspectj\aspectjweaver\1.8.13\ad94df2a28d658a40dc27bbaff6a1ce5fbf04e9b\aspectjweaver-1.8.13.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.zaxxer\HikariCP\2.7.9\a83113d2c091d0d0f853dad3217bd7df3beb6ae3\HikariCP-2.7.9.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.hibernate.common\hibernate-commons-annotations\5.0.1.Final\71e1cff3fcb20d3b3af4f3363c3ddb24d33c6879\hibernate-commons-annotations-5.0.1.Final.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.2.Final\3789d00e859632e6c6206adc0c71625559e6e3b0\jboss-logging-3.3.2.Final.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.hibernate.javax.persistence\hibernate-jpa-2.1-api\1.0.2.Final\52afb5762c704a6b586e27742470c08f91877fc1\hibernate-jpa-2.1-api-1.0.2.Final.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.javassist\javassist\3.22.0-GA\3e83394258ae2089be7219b971ec21a8288528ad\javassist-3.22.0-GA.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\antlr\antlr\2.7.7\83cd2cd674a217ade95a4bb83a8a14f351f48bd0\antlr-2.7.7.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.jboss\jandex\2.0.3.Final\bfc4d6257dbff7a33a357f0de116be6ff951d849\jandex-2.0.3.Final.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.3.4\3d5f48f10bbe4eb7bd862f10c0583be2e0053c6\classmate-1.3.4.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\dom4j\dom4j\1.6.1\5d3ccc056b6f056dbf0dddfdf43894b9065a8f94\dom4j-1.6.1.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf\3.0.9.RELEASE\64185cca50ac808ad034841c84b4013f955465d2\thymeleaf-3.0.9.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.10.0\f7e631ccf49cfc0aefa4a2a728da7d374c05bd3c\log4j-to-slf4j-2.10.0.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.25\af5364cd6679bfffb114f0dec8a157aaa283b76\jul-to-slf4j-1.7.25.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.25\da76ca59f6a57ee3102f8f9bd9cee742973efa8a\slf4j-api-1.7.25.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.0.7.RELEASE\699016ddf454c2c167d9f84ae5777eccadf54728\spring-jcl-5.0.7.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.9.0\7c10d545325e3a6e72e06381afe469fd40eb701\jackson-annotations-2.9.0.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.9.6\4e393793c37c77e042ccc7be5a914ae39251b365\jackson-core-2.9.6.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.attoparser\attoparser\2.0.4.RELEASE\5cf02c4d8303a81f0c80971bb1dcd40d3ba96009\attoparser-2.0.4.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.unbescape\unbescape\1.1.5.RELEASE\46dc644ea9c234317d926ebac5bf5d8f114dc1ba\unbescape-1.1.5.RELEASE.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\E080978\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.10.0\fec5797a55b786184a537abd39c3fa1449d752d6\log4j-api-2.10.0.jar" com.mastercard.ayman.imagepackt.ImagePacktApplication
12:37:05.891 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
12:37:05.898 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
12:37:05.898 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/E080978/Downloads/Mastercard%20Image/demo/out/production/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-06-20 12:37:06.301 INFO 23152 --- [ restartedMain] c.m.a.imagepackt.ImagePacktApplication : Starting ImagePacktApplication on GH-6C9HNH2 with PID 23152 (started by E080978 in C:\Users\E080978\Downloads\Mastercard Image\demo)
2018-06-20 12:37:06.302 INFO 23152 --- [ restartedMain] c.m.a.imagepackt.ImagePacktApplication : No active profile set, falling back to default profiles: default
2018-06-20 12:37:06.374 INFO 23152 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#17c49070: startup date [Wed Jun 20 12:37:06 IST 2018]; root of context hierarchy
2018-06-20 12:37:07.824 INFO 23152 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$b97b663c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-20 12:37:08.184 INFO 23152 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-06-20 12:37:08.349 INFO 23152 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-06-20 12:37:08.409 INFO 23152 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-06-20 12:37:08.431 INFO 23152 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-06-20 12:37:08.523 INFO 23152 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-06-20 12:37:08.524 INFO 23152 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-06-20 12:37:08.566 INFO 23152 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-06-20 12:37:08.713 INFO 23152 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-06-20 12:37:09.315 INFO 23152 --- [ restartedMain] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#2c5eb52e'
2018-06-20 12:37:09.319 INFO 23152 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-06-20 12:37:10.108 WARN 23152 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2018-06-20 12:37:10.246 INFO 23152 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-06-20 12:37:10.284 INFO 23152 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-06-20 12:37:10.285 INFO 23152 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-06-20 12:37:10.289 INFO 23152 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-06-20 12:37:10.302 INFO 23152 --- [ restartedMain] c.m.a.imagepackt.ImagePacktApplication : Started ImagePacktApplication in 4.384 seconds (JVM running for 5.279)
2018-06-20 12:37:10.308 INFO 23152 --- [ Thread-10] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#17c49070: startup date [Wed Jun 20 12:37:06 IST 2018]; root of context hierarchy
2018-06-20 12:37:10.312 INFO 23152 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-06-20 12:37:10.313 INFO 23152 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-06-20 12:37:10.314 INFO 23152 --- [ Thread-10] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-06-20 12:37:10.315 INFO 23152 --- [ Thread-10] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'
2018-06-20 12:37:10.320 WARN 23152 --- [ Thread-10] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]
2018-06-20 12:37:10.321 INFO 23152 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-06-20 12:37:10.323 INFO 23152 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0
According to me these two lines are the problem:
1.The first line
Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$b97b663c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-20 12:37:08.184 INFO 23152 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource :
2.The second line
2018-06-20 12:37:10.320 WARN 23152 --- [ Thread-10] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]
I have not done any configuration on the database. Do I need to change database properties for the same?
This is expected. Your app doesn't have any web dependencies, it's simply starting up, running and closing.
Add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
If you want an embedded container to run.
I should add you will not see this with < 2.0 and those starters, since boot 2.0 and WebFlux Spring boot starter web is no longer a transitive dependency. You must specify it.
... add ";DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" to the db URL ...
Add to application.properties file:
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
probably you need to exclude datasource(if you already have your own datasource configured for application) auto configuration in main class.
#SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})

Spring boot stops as I write some JPA queries in the repository

I am using spring boot with H2 database. My application stops with below text on console.
2016-08-01 10:36:08.610 INFO 3920 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-08-01 10:36:08.651 INFO 3920 --- [ost-startStop-1] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2016-08-01 10:36:08.651 INFO 3920 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-08-01 10:36:08.651 INFO 3920 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-08-01 10:36:08.801 INFO 3920 --- [ost-startStop-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-08-01 10:36:09.031 INFO 3920 --- [ost-startStop-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2016-08-01 10:36:09.131 INFO 3920 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-08-01 10:36:09.291 INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-08-01 10:36:09.291 INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-08-01 10:36:09.301 INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000396: Updating schema
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: TEST.PUBLIC.EMAILDATA
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [quantity, emailto, id, autostart, emailfrom]
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [primary_key_2]
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: TEST.PUBLIC.STATUS
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [exchangefile, consolidate, processdate, aggregateall, scriptmaster, sendmail, id, insiderstrade]
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [primary_key_9]
2016-08-01 10:36:09.311 INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000232: Schema update complete
My repository is:
#Transactional
public interface EmailDataRepository extends JpaRepository<EmailData,Long>{
#Query("SELECT p FROM EmailData P")
public EmailData findLastRow();
}
And DBConfig is:
#Configuration
#EnableTransactionManagement
#ComponentScan("com.demo.*")
#PropertySource("classpath:application.properties")
#EntityScan(basePackages = {"com.demo.model"})
#EnableJpaRepositories("com.demo.repository.main")
public class DBConfig {....}
Model:
#Entity
#Table(name="EmailData")
public class EmailData {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
Long id;
private String emailTo;
private String emailFrom;
private String quantity;
private Boolean autoStart;
...}
Your H2 database url should have the following configuration
DB_CLOSE_ON_EXIT=FALSE
Spring Boot documentation has a quote:
If, for whatever reason, you do configure the connection URL for an embedded database, care should be taken to ensure that the database’s automatic shutdown is disabled. If you’re using H2 you should use DB_CLOSE_ON_EXIT=FALSE to do so. If you’re using HSQLDB, you should ensure that shutdown=true is not used. Disabling the database’s automatic shutdown allows Spring Boot to control when the database is closed, thereby ensuring that it happens once access to the database is no longer needed.

Resources