Spring session table not created in Docker container - spring

When I'm launching my Spring application from my IDE (IntelliJ), there is no problem with the creation of all the tables including the Spring Session table.
However, when I'm launching it with the generated jar (with the same things inside) from my docker containers, it creates my tables excluding Spring Session one.
I receive this error, telling me that the spring session does not exist:
app | 09:43:33.837 [HikariPool-1 housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
app | 09:43:33.837 [HikariPool-1 housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Fill pool skipped, pool is at sufficient level.
app | 09:44:00.005 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
app | 09:44:00.006 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Opened new EntityManager [SessionImpl(1059542725<open>)] for JPA transaction
app | 09:44:00.014 [pool-1-thread-1] DEBUG org.hibernate.engine.transaction.internal.TransactionImpl - On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
app | 09:44:00.015 [pool-1-thread-1] DEBUG org.hibernate.engine.transaction.internal.TransactionImpl - begin
app | 09:44:00.019 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#3b3c4387]
app | 09:44:00.021 [pool-1-thread-1] DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL update
app | 09:44:00.022 [pool-1-thread-1] DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?]
db | 2021-09-04 09:44:00.037 UTC [82] ERROR: relation "spring_session" does not exist at character 13
db | 2021-09-04 09:44:00.037 UTC [82] STATEMENT: DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < $1
app | 09:44:00.280 [pool-1-thread-1] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 11 bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
app | 09:44:00.281 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'DB2'
app | 09:44:00.289 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'Derby'
app | 09:44:00.291 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'H2'
app | 09:44:00.293 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'HDB'
app | 09:44:00.295 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'HSQL'
app | 09:44:00.297 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'Informix'
app | 09:44:00.298 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'MS-SQL'
app | 09:44:00.299 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'MySQL'
app | 09:44:00.300 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'Oracle'
app | 09:44:00.302 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'PostgreSQL'
app | 09:44:00.303 [pool-1-thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'Sybase'
app | 09:44:00.305 [pool-1-thread-1] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Looking up default SQLErrorCodes for DataSource [com.zaxxer.hikari.HikariDataSource#77eb5790]
app | 09:44:00.308 [pool-1-thread-1] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'PostgreSQL' found
app | 09:44:00.309 [pool-1-thread-1] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - Caching SQL error codes for DataSource [com.zaxxer.hikari.HikariDataSource#77eb5790]: database product name is 'PostgreSQL'
app | 09:44:00.310 [pool-1-thread-1] DEBUG org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQL state '42P01', error code '0', message [ERROR: relation "spring_session" does not exist
app | Position: 13]; SQL was [DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?] for task [PreparedStatementCallback]
app | 09:44:00.312 [pool-1-thread-1] DEBUG org.springframework.transaction.support.TransactionTemplate - Initiating transaction rollback on application exception
app | org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist
app | Position: 13
app | at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
app | at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
app | at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541)
app | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:960)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1015)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1025)
app | at org.springframework.session.jdbc.JdbcIndexedSessionRepository.lambda$cleanUpExpiredSessions$8(JdbcIndexedSessionRepository.java:587)
app | at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
app | at org.springframework.session.jdbc.JdbcIndexedSessionRepository.cleanUpExpiredSessions(JdbcIndexedSessionRepository.java:587)
app | at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
app | at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:95)
app | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
app | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
app | at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
app | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
app | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
app | at java.base/java.lang.Thread.run(Thread.java:829)
app | Caused by: org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist
app | Position: 13
app | at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552)
app | at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2284)
app | at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:322)
app | at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
app | at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
app | at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
app | at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130)
app | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
app | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
app | at org.springframework.jdbc.core.JdbcTemplate.lambda$update$2(JdbcTemplate.java:965)
app | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651)
app | ... 14 common frames omitted
app | 09:44:00.316 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Initiating transaction rollback
app | 09:44:00.317 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Rolling back JPA transaction on EntityManager [SessionImpl(1059542725<open>)]
app | 09:44:00.318 [pool-1-thread-1] DEBUG org.hibernate.engine.transaction.internal.TransactionImpl - rolling back
app | 09:44:00.328 [pool-1-thread-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Closing JPA EntityManager [SessionImpl(1059542725<open>)] after transaction
app | 09:44:00.330 [pool-1-thread-1] ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task
app | org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist
app | Position: 13
app | at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
app | at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
app | at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541)
app | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:960)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1015)
app | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1025)
app | at org.springframework.session.jdbc.JdbcIndexedSessionRepository.lambda$cleanUpExpiredSessions$8(JdbcIndexedSessionRepository.java:587)
app | at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
app | at org.springframework.session.jdbc.JdbcIndexedSessionRepository.cleanUpExpiredSessions(JdbcIndexedSessionRepository.java:587)
app | at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
app | at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:95)
app | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
app | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
app | at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
app | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
app | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
app | at java.base/java.lang.Thread.run(Thread.java:829)
app | Caused by: org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist
app | Position: 13
app | at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552)
app | at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2284)
app | at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:322)
app | at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
app | at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
app | at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
app | at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130)
app | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
app | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
app | at org.springframework.jdbc.core.JdbcTemplate.lambda$update$2(JdbcTemplate.java:965)
app | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651)
app | ... 14 common frames omitted
Here is my configuration :
application.properties
server.port=8080
# Database configuration
spring.datasource.url = jdbc:postgresql://db:5432/mynotes
spring.datasource.username = postgres
spring.datasource.password = postgres
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
# JPA configuration
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create
#Pour ne pas avoir la ligne d'erreur : SOURCE "https://stackoverflow.com/questions/4588755/disabling-contextual-lob-creation-as-createclob-method-threw-error"
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
# Session configuration
spring.session.store-type=jdbc
spring.session.jdbc.initialize-schema=always
spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-postgresql.sql
spring.session.jdbc.table-name=SPRING_SESSION # Name of the database table used to store sessions.
# Pour se connecter avec l'appli mobile
server.address=0.0.0.0
docker-compose.yml
version: '2'
services:
app:
image: "magnan/mynotes:${VERSION}"
build:
context: ./App
container_name: app
depends_on:
- db
ports:
- "8080:8080"
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/mynotes
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=create
db:
image: 'postgres:13.1'
container_name: db
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- ./Db/create_db_mynotes.sql:/docker-entrypoint-initdb.d/create_db_mynotes.sql
App/Dockerfile
FROM openjdk:11
VOLUME /tmp
COPY *.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
create_db_mynotes.sql
CREATE DATABASE mynotes;
GRANT ALL PRIVILEGES ON DATABASE mynotes TO postgres;
Do you have any ideas why this is happening in containers and not in IntelliJ and how to solve it ?
Thanks a lot for your help!

An example of how to create a new instance can be seen below:
JdbcTemplate jdbcTemplate = new JdbcTemplate();
// ... configure jdbcTemplate ...
TransactionTemplate transactionTemplate = new TransactionTemplate();
// ... configure transactionTemplate ...
JdbcIndexedSessionRepository sessionRepository =
new JdbcIndexedSessionRepository(jdbcTemplate, transactionTemplate);
For additional information on how to create and configure JdbcTemplate and TransactionTemplate, refer to the Spring Framework Reference Documentation.
By default, this implementation uses SPRING_SESSION and SPRING_SESSION_ATTRIBUTES tables to store sessions. Note that the table name can be customized using the setTableName(String) method. In that case the table used to store attributes will be named using the provided table name, suffixed with _ATTRIBUTES. Depending on your database, the table definition can be described as below:
CREATE TABLE SPRING_SESSION (
PRIMARY_ID CHAR(36) NOT NULL,
SESSION_ID CHAR(36) NOT NULL,
CREATION_TIME BIGINT NOT NULL,
LAST_ACCESS_TIME BIGINT NOT NULL,
MAX_INACTIVE_INTERVAL INT NOT NULL,
EXPIRY_TIME BIGINT NOT NULL,
PRINCIPAL_NAME VARCHAR(100),
CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID)
);
CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID);
CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME);
CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME);
CREATE TABLE SPRING_SESSION_ATTRIBUTES (
SESSION_PRIMARY_ID CHAR(36) NOT NULL,
ATTRIBUTE_NAME VARCHAR(200) NOT NULL,
ATTRIBUTE_BYTES BYTEA NOT NULL,
CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID,
ATTRIBUTE_NAME),
CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID)
REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE
);
CREATE INDEX SPRING_SESSION_ATTRIBUTES_IX1 ON SPRING_SESSION_ATTRIBUTES (SESSION_PRIMARY_ID);
Due to the differences between the various database vendors, especially when it comes to storing binary data, make sure to use SQL script specific to your database. Scripts for most major database vendors are packaged as org/springframework/session/jdbc/schema-*.sql, where * is the target database type.

Related

Problem with hibernate.hbm2ddl.auto in a migration

I have migrated a spring-boot project from MySQL to SQL Server. I don't have the necessary roles to use hibernate.hbm2ddl.auto = update.
How can I update without having access to sysadmin?
I need to update because I can't lose the records
2021-07-21 | 13:30:17.660 | INFO | main | o.h.t.h.SchemaUpdate | HHH000228: Running hbm2ddl schema update
2021-07-21 | 13:30:17.692 | WARN | main | .e.j.s.SqlExceptionHelper | SQL Error: 229, SQLState: S0005
2021-07-21 | 13:30:17.692 | ERROR | main | .e.j.s.SqlExceptionHelper | The SELECT permission was denied on the object 'sequences', database 'mssqlsystemresource', schema 'sys'.
2021-07-21 | 13:30:17.692 | WARN | main | ddedWebApplicationContext | Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2021-07-21 | 13:30:17.692 | INFO | main | o.a.c.c.StandardService | Stopping service [Tomcat]
I don't know how you are invoking hbm2ddl but you can specify an output file and then apply these statements manually. You can configure this through the javax.persistence.schema-generation.scripts.create-target parameter. See the documentation for details: https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl

Unable to connect to RDS from Elastic Beanstalk Docker

My spring boot app deployed in Elastic Beanstalks docker is unable to connect to external RDS. It always stuck at "com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting..." during app startup.
Dockerfile
(I added the db connection details in ENTRYPOINT for troubleshooting purpose)
FROM openjdk:8
WORKDIR "/mrbs"
ARG JAR_FILE=target/*jar
COPY ${JAR_FILE} ./app.jar
EXPOSE 8080
#CMD ["java","-jar","./app.jar"]
ENTRYPOINT ["java","-jar","./app.jar","--spring.datasource.url=jdbc:mysql://[security].[security].ap-southeast-1.rds.amazonaws.com:3306/mrbs?serverTimezone=GMT%2B8","--spring.datasource.password=[security]","--spring.datasource.username=[security]","--logging.file.path=/mrbs/logs/"]
Dockerrun.aws.json
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "api",
"image": "[security]/mrbs-backend",
"hostname": "api",
"essential": true,
"memory": 128
}
]
}
.travis.yml
language: generic
sudo: required
services:
- docker
before_install:
install: skip
before_script:
script:
- mvn -f mrbs-backend clean package
- docker build -t [security]/mrbs-backend ./mrbs-backend
- echo "$DOCKER_PASSWORD" |docker login -u "$DOKCER_ID" --password-stdin
- docker push [security]/mrbs-backend
deploy:
skip_cleanup: true
provider: elasticbeanstalk
region: ap-southeast-1
#app: mrbs-docker
app: mrbs
env: Mrbs-env-3
bucket_name: elasticbeanstalk-ap-southeast-1-[security]351
bucket_patch: mrbs
on:
branch: master
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_SECRET_KEY
Added security group mrbs-intra-docker to both RDS and Elastic Beanstalk
RDS Security Group
(image),
Elastic Beanstalk Security Group
(image),
EC2 Security Group
(image),
When I check the log from elastic beanstalk, it shows that spring boot app stuck at "com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting..." during startup.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.3.RELEASE)
2020-11-01 09:14:16,590 [main] INFO c.j.m.MeetingRoomBookingSystemApplication - Starting MeetingRoomBookingSystemApplication v1.0 on api with PID 1 (/mrbs/app.jar started by root in /mrbs)
2020-11-01 09:14:16,599 [main] DEBUG c.j.m.MeetingRoomBookingSystemApplication - Running with Spring Boot v2.3.3.RELEASE, Spring v5.2.8.RELEASE
2020-11-01 09:14:16,600 [main] INFO c.j.m.MeetingRoomBookingSystemApplication - The following profiles are active: dev
2020-11-01 09:14:19,408 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-01 09:14:19,729 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 294ms. Found 7 JPA repository interfaces.
2020-11-01 09:14:21,469 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#c03cf28' 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-11-01 09:14:21,513 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$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-11-01 09:14:22,602 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
2020-11-01 09:14:22,639 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"]
2020-11-01 09:14:22,640 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2020-11-01 09:14:22,640 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-11-01 09:14:22,826 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2020-11-01 09:14:22,827 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 6052 ms
2020-11-01 09:14:24,415 [main] INFO o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
2020-11-01 09:14:24,516 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
However, If I directly run the docker from EC2 command line, the spring boot can be started successfully, which means ec2 instance is able to connect to rds using the same image...
[ec2-user#ip-172-31-24-202 ~]$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
[secruity]/mrbs-backend latest bd84014e90df 9 minutes ago 570MB
amazon/amazon-ecs-agent latest ebac5fda27cb 8 weeks ago 67MB
[ec2-user#ip-172-31-24-202 ~]$ docker run [secruity]/mrbs-backend
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.3.RELEASE)
2020-11-01 09:36:39,075 [main] INFO c.j.m.MeetingRoomBookingSystemApplication - Starting MeetingRoomBookingSystemApplication v1.0 on 1d93b8a14d12 with PID 1 (/mrbs/app.jar started by root in /mrbs)
2020-11-01 09:36:39,087 [main] DEBUG c.j.m.MeetingRoomBookingSystemApplication - Running with Spring Boot v2.3.3.RELEASE, Spring v5.2.8.RELEASE
2020-11-01 09:36:39,088 [main] INFO c.j.m.MeetingRoomBookingSystemApplication - The following profiles are active: dev
2020-11-01 09:36:44,035 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-01 09:36:44,558 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 474ms. Found 7 JPA repository interfaces.
2020-11-01 09:36:47,066 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#c03cf28' 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-11-01 09:36:47,107 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$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-11-01 09:36:49,047 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
2020-11-01 09:36:49,099 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"]
2020-11-01 09:36:49,106 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2020-11-01 09:36:49,107 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-11-01 09:36:49,546 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2020-11-01 09:36:49,549 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 10161 ms
2020-11-01 09:36:51,992 [main] INFO o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
2020-11-01 09:36:52,141 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2020-11-01 09:36:54,622 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
filePath=/mrbs/logs/
2020-11-01 09:36:55,296 [main] DEBUG com.jiangwensi.mrbs.AppContext - setApplicationContext is called
2020-11-01 09:36:55,528 [task-1] INFO o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [name: default]
2020-11-01 09:36:56,161 [main] WARN o.s.b.a.o.j.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-11-01 09:36:58,427 [task-1] INFO org.hibernate.Version - HHH000412: Hibernate ORM core version 5.4.20.Final
2020-11-01 09:36:58,874 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for Ant [pattern='/auth/signUp', POST]
2020-11-01 09:36:58,887 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for Ant [pattern='/auth/verifyEmail', GET]
2020-11-01 09:36:58,888 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for Ant [pattern='/auth/requestResetForgottenPassword', POST]
2020-11-01 09:36:58,888 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for Ant [pattern='/auth/resetForgottenPassword', POST]
2020-11-01 09:36:58,889 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for Ant [pattern='/auth/resetPassword', POST]
2020-11-01 09:36:58,892 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'authenticated', for any request
2020-11-01 09:36:59,011 [main] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Validated configuration attributes
2020-11-01 09:36:59,020 [main] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Validated configuration attributes
2020-11-01 09:36:59,036 [main] INFO o.s.s.w.DefaultSecurityFilterChain - Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#31bcf236, org.springframework.security.web.context.SecurityContextPersistenceFilter#4c51cf28, org.springframework.security.web.header.HeaderWriterFilter#289710d9, org.springframework.web.filter.CorsFilter#4b3ed2f0, org.springframework.security.web.authentication.logout.LogoutFilter#3549bca9, com.jiangwensi.mrbs.security.LoginAuthenticationFilter#4fad9bb2, com.jiangwensi.mrbs.security.JwtAuthenticationFilter#517d4a0d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#5143c662, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#71c27ee8, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#7862f56, org.springframework.security.web.session.SessionManagementFilter#3da30852, org.springframework.security.web.access.ExceptionTranslationFilter#4eb386df, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#134d26af]
2020-11-01 09:36:59,324 [main] DEBUG o.s.s.a.i.a.MethodSecurityInterceptor - Validated configuration attributes
2020-11-01 09:36:59,643 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 6.1.5.Final
2020-11-01 09:37:01,174 [task-1] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-11-01 09:37:03,566 [task-1] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-11-01 09:37:05,670 [main] DEBUG o.s.s.c.a.a.c.AuthenticationConfiguration$EnableGlobalAuthenticationAutowiredConfigurer - Eagerly initializing {webSecurityConfigurator=com.jiangwensi.mrbs.security.WebSecurityConfigurator$$EnhancerBySpringCGLIB$$aa3555ad#1a20270e}
2020-11-01 09:37:05,692 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"]
2020-11-01 09:37:06,111 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
2020-11-01 09:37:06,136 [main] INFO o.s.d.r.c.DeferredRepositoryInitializationListener - Triggering deferred initialization of Spring Data repositories…
2020-11-01 09:37:09,726 [task-1] INFO o.h.e.t.j.p.i.JtaPlatformInitiator - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-11-01 09:37:09,802 [task-1] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-11-01 09:37:12,036 [main] INFO o.s.d.r.c.DeferredRepositoryInitializationListener - Spring Data repositories initialized!
2020-11-01 09:37:12,065 [main] INFO c.j.m.MeetingRoomBookingSystemApplication - Started MeetingRoomBookingSystemApplication in 36.293 seconds (JVM running for 42.707)
2020-11-01 09:37:12,073 [main] DEBUG c.j.mrbs.InitializeApplicationData - onApplicationEvent is called
Based on the comments.
The issue was caused by not sufficient memory allocated to the container.
The solution was to increase the memory.

Getting NullPonterException while trying to stop apache-activemq?

I am unable to shutdown my activemq gracefully after enabling jmx. Please help and tell me what am I doing wrong. Here is what I am trying to do.
start activemq:-
[mwapp#JMNGD1BAO150V02 ~]$ /app/apache-activemq-5.14.0/bin/activemq start xbean:/app/apache-activemq-5.14.0/conf/activemq-security.xml
INFO: Loading '/app/apache-activemq-5.14.0//bin/env'
INFO: Using java '/usr/java/jre1.7.0_79//bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/app/apache-activemq-5.14.0//data/activemq.pid' (pid '16917')
activemq.log:- To me it's looking fine
2017-10-12 13:48:18,936 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1#2142b533: startup date [Thu Oct 12 13:48:18 IST 2017]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
2017-10-12 13:48:20,008 | INFO | Loading properties file from URL [file:/app/apache-activemq-5.14.0//conf/credentials-enc.properties] | org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer | main
2017-10-12 13:48:20,975 | INFO | Loaded the Bouncy Castle security provider. | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:21,283 | INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/jms_nas/kahadb] | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:21,308 | INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi | org.apache.activemq.broker.jmx.ManagementContext | JMX connector
2017-10-12 13:48:21,594 | INFO | KahaDB is version 6 | org.apache.activemq.store.kahadb.MessageDatabase | main
2017-10-12 13:48:21,653 | INFO | Recovering from the journal #1105:27118028 | org.apache.activemq.store.kahadb.MessageDatabase | main
2017-10-12 13:48:21,657 | INFO | Recovery replayed 58 operations from the journal in 0.046 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | main
2017-10-12 13:48:21,719 | INFO | PListStore:[/app/apache-activemq-5.14.0/data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | main
2017-10-12 13:48:21,903 | INFO | Apache ActiveMQ 5.14.0 (localhost, ID:JMNGD1BAO150V02-59661-1507796301746-0:1) is starting | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:22,786 | INFO | Listening for connections at: ssl://JMNGD1BAO150V02:61616?needClientAuth=true&maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | main
2017-10-12 13:48:22,787 | INFO | Connector ssl started | org.apache.activemq.broker.TransportConnector | main
2017-10-12 13:48:22,787 | INFO | Apache ActiveMQ 5.14.0 (localhost, ID:JMNGD1BAO150V02-59661-1507796301746-0:1) started | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:22,787 | INFO | For help or more information please see: http://activemq.apache.org | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:22,788 | WARN | Store limit is 102400 mb (current store usage is 1397 mb). The data directory: /jms_nas/kahadb only has 91534 mb of usable space. - resetting to maximum available disk space: 91534 mb | org.apache.activemq.broker.BrokerService | main
2017-10-12 13:48:23,646 | INFO | No Spring WebApplicationInitializer types detected on classpath | /admin | main
2017-10-12 13:48:23,755 | INFO | ActiveMQ WebConsole available at http://localhost:8161/ | org.apache.activemq.web.WebConsoleStarter | main
2017-10-12 13:48:23,755 | INFO | ActiveMQ Jolokia REST API available at http://localhost:8161/api/jolokia/ | org.apache.activemq.web.WebConsoleStarter | main
2017-10-12 13:48:23,799 | INFO | Initializing Spring FrameworkServlet 'dispatcher' | /admin | main
2017-10-12 13:48:24,068 | INFO | No Spring WebApplicationInitializer types detected on classpath | /api | main
2017-10-12 13:48:24,185 | INFO | jolokia-agent: Using policy access restrictor classpath:/jolokia-access.xml | /api | main
stop activemq:-
[mwapp#JMNGD1BAO150V02 ~]$ /app/apache-activemq-5.14.0/bin/activemq stop xbean:/app/apache-activemq-5.14.0/conf/activemq-security.xml
INFO: Loading '/app/apache-activemq-5.14.0//bin/env'
INFO: Using java '/usr/java/jre1.7.0_79//bin/java'
INFO: Waiting at least 30 seconds for regular process termination of pid '16917' :
Java Runtime: Oracle Corporation 1.7.0_79 /usr/java/jre1.7.0_79
Heap sizes: current=63488k free=61608k max=932352k
JVM args: -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/app/apache-activemq-5.14.0//conf/login.config -Dactivemq.classpath=/app/apache-activemq-5.14.0//conf:/app/apache-activemq-5.14.0//../lib/: -Dactivemq.home=/app/apache-activemq-5.14.0/ -Dactivemq.base=/app/apache-activemq-5.14.0/ -Dactivemq.conf=/app/apache-activemq-5.14.0//conf -Dactivemq.data=/app/apache-activemq-5.14.0//data
Extensions classpath:
[/app/apache-activemq-5.14.0/lib,/app/apache-activemq-5.14.0/lib/camel,/app/apache-activemq-5.14.0/lib/optional,/app/apache-activemq-5.14.0/lib/web,/app/apache-activemq-5.14.0/lib/extra]
ACTIVEMQ_HOME: /app/apache-activemq-5.14.0
ACTIVEMQ_BASE: /app/apache-activemq-5.14.0
ACTIVEMQ_CONF: /app/apache-activemq-5.14.0/conf
ACTIVEMQ_DATA: /app/apache-activemq-5.14.0/data
Connecting to JMX URL: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
ERROR: java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.activemq.console.command.AbstractCommand.handleException(AbstractCommand.java:167)
at org.apache.activemq.console.command.AbstractJmxCommand.execute(AbstractJmxCommand.java:390)
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:154)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:63)
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
at org.apache.activemq.console.Main.main(Main.java:115)
...............................
INFO: Regular shutdown not successful, sending SIGKILL to process
INFO: sending SIGKILL to pid '16917'
As you can see, the system is forcefully shutting down using pid which is not expected. I am currently using apache-activemq-5.14.0 and the configuration file will look something like below. I am not sure why activemq gave two separate file to enable JMX i.e. env and activemq-security.xml. Or the env file has some different role to play. I read the documentation, and I got more confuse when they mention from V.5.12.0 onwards they are supporting OCSP. Do I need to enable that too?
${ACTIVEMQ_HOME}/bin/env
#!/bin/sh
# Active MQ installation dirs
# ACTIVEMQ_HOME="<Installationdir>/"
# ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
# ACTIVEMQ_CONF="$ACTIVEMQ_BASE/conf"
# ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data"
# ACTIVEMQ_TMP="$ACTIVEMQ_BASE/tmp"
ACTIVEMQ_OPTS_MEMORY="-Xms64M -Xmx1G"
if [ -z "$ACTIVEMQ_OPTS" ] ; then
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config"
fi
#ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.audit=true"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.port=1099"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=true"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"
#ACTIVEMQ_SUNJMX_CONTROL="--jmxurl service:jmx:rmi:///jndi/rmi://127.0.0.1:1099/jmxrmi --jmxuser controlRole --jmxpassword abcd1234"
ACTIVEMQ_SUNJMX_CONTROL=""
if [ -z "$ACTIVEMQ_QUEUEMANAGERURL" ]; then
ACTIVEMQ_QUEUEMANAGERURL="--amqurl tcp://localhost:61616"
fi
if [ -z "$ACTIVEMQ_SSL_OPTS" ] ; then
#ACTIVEMQ_SSL_OPTS="-Djava.security.properties=$ACTIVEMQ_CONF/java.security"
ACTIVEMQ_SSL_OPTS=""
fi
#ACTIVEMQ_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
if [ -z "$ACTIVEMQ_KILL_MAXSECONDS" ]; then
ACTIVEMQ_KILL_MAXSECONDS=30
fi
ACTIVEMQ_USER=""
# ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA/activemq.pid"
JAVA_HOME="/usr/java/jre1.7.0_79/"
${ACTIVEMQ_HOME}/conf/activemq-security.xml
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
----------------------------------------------
<managementContext>
<!--managementContext createConnector="true" connectorPort="1099"/-->
<managementContext createConnector="true">
<property xmlns="http://www.springframework.org/schema/beans" name="environment">
<map xmlns="http://www.springframework.org/schema/beans">
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.password.file" value="${activemq.base}/conf/jmx.password"/>
<entry xmlns="http://www.springframework.org/schema/beans" key="jmx.remote.x.access.file" value="${activemq.base}/conf/jmx.access"/>
</map>
</property>
</managementContext>
</managementContext>
----------------------------------------------
<shutdownHooks>
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook"/>
</shutdownHooks>
</broker>

Spring Data / JPA / Hibernate : Not committing changes

I'm trying to execute a query which has to delete items from a sub select.
Environment :
Wildfly 8.2
Spring Framework 4.1.6
Spring Data 1.8.0
Hibernate 4.3.10
MySQL 5
Here's the repository :
public interface MySecondEntityRepository extends JpaRepository<MySecondEntity, UUID> {
#Modifying
#Transactional(propagation = Propagation.REQUIRES_NEW)
#Query("DELETE FROM MySecondEntity e WHERE e.uuid IN ("
+ "SELECT e2.uuid "
+ "FROM MySecondEntity e2, MyEntity e1 "
+ "WHERE e2.entityUUID = e1.uuid "
+ "AND e1.uuid = :uuid "
+ "AND e1.*** = ..."
+ "AND e1.*** = ..."
+ ")")
public void deleteByEntityUUID(#Param("uuid") UUID entityUUID, ...);
}
Here's the transaction manager's XML definition :
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
where entityManagerFactory is a LocalContainerEntityManagerFactoryBean.
I'm using them not to be dependent of the provider.
In the logs, I can see :
SQL | insert into HT_my_entity select ...
SQL | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
When I execute manually the select ..., I get the correct uuids to be deleted. but when spring/hibernate execute them, the transaction does not commit even with Propagation.REQUIRES_NEW. No exception thrown.
Full logs :
14:41:45,073 | DEBUG | AnnotationTransactionAttri:108 | Adding transactional method 'DefaultJpaRepositoryImpl.deleteByEntityUUID' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,073 | DEBUG | JpaTransactionManager :367 | Creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; ''
14:41:45,074 | DEBUG | JpaTransactionManager :371 | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl#cd414] for JPA transaction
14:41:45,075 | DEBUG | AbstractTransactionImpl :160 | begin
14:41:45,075 | DEBUG | LogicalConnectionImpl :226 | Obtaining JDBC connection
14:41:45,075 | DEBUG | LogicalConnectionImpl :232 | Obtained JDBC connection
14:41:45,076 | DEBUG | JdbcTransaction :69 | initial autocommit status: true
14:41:45,076 | DEBUG | JdbcTransaction :71 | disabling autocommit
14:41:45,076 | DEBUG | JpaTransactionManager :403 | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#7d7135]
14:41:45,078 | DEBUG | JpaTransactionManager :334 | Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl#cd414] for JPA transaction
14:41:45,079 | DEBUG | JpaTransactionManager :417 | Suspending current transaction, creating new transaction with name [xxx.spring.jpa.factory.DefaultJpaRepositoryImpl.deleteByEntityUUID]
14:41:45,082 | DEBUG | JpaTransactionManager :371 | Opened new EntityManager [org.hibernate.jpa.internal.EntityManagerImpl#35e880] for JPA transaction
14:41:45,082 | DEBUG | AbstractTransactionImpl :160 | begin
14:41:45,082 | DEBUG | LogicalConnectionImpl :226 | Obtaining JDBC connection
14:41:45,083 | DEBUG | LogicalConnectionImpl :232 | Obtained JDBC connection
14:41:45,083 | DEBUG | JdbcTransaction :69 | initial autocommit status: true
14:41:45,083 | DEBUG | JdbcTransaction :71 | disabling autocommit
14:41:45,084 | DEBUG | JpaTransactionManager :403 | Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#1b46a77]
14:41:45,223 | DEBUG | SQL :109 | insert into HT_my_entity select my_second_0_.uuid as uuid from my_second_entity my_second_0_ where my_second_0_.uuid in (select my_second_1_.uuid from my_second_entity my_second_1_ cross join my_entity my_entity_2_ where my_second_1_.entity_uuid=my_entity_2_.uuid and my_entity_2_.uuid=?)
14:41:45,232 | DEBUG | SQL :109 | delete from my_entity where uuid IN (select uuid FROM HT_my_entity);
14:41:45,333 | DEBUG | JpaTransactionManager :755 | Initiating transaction commit
14:41:45,334 | DEBUG | JpaTransactionManager :512 | Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl#35e880]
14:41:45,335 | DEBUG | AbstractTransactionImpl :175 | committing
14:41:45,388 | DEBUG | JdbcTransaction :113 | committed JDBC Connection
14:41:45,389 | DEBUG | JdbcTransaction :126 | re-enabling autocommit
14:41:45,393 | DEBUG | JpaTransactionManager :600 | Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl#35e880] after transaction
14:41:45,394 | DEBUG | EntityManagerFactoryUtils :432 | Closing JPA EntityManager
14:41:45,396 | DEBUG | LogicalConnectionImpl :246 | Releasing JDBC connection
14:41:45,397 | DEBUG | LogicalConnectionImpl :264 | Released JDBC connection
What I tried :
Propagation.REQUIRED and Propagation.REQUIRES_NEW
.flush() after the method's call
Unwrap the subquery to test it. It works correctly.
Update Spring Data / Hibernate
Note :
I do not include MySecondEntity in MyEntity for performance reason. A MyEntity can have 10k+ MySecondEntity. I know I can use lazy fetching but actually, entities are mapped to data transfert object and this cause issues to mapping process. Also, I do not want the retrieve all the data to delete them.
<tx:annotation-driven/> is defined
<aop:aspectj-autoproxy/> is defined
The method is called directly from a #RestController.

Grails Rest Client Builder Throwing OperationNotSupported

I am trying to develop a Grails application to call some REST services ...
I am attempting to use the Grails Rest Client Builder Plugin ...
I have tried on several versions of Grails ... currently on most recent version ... 2.3.7 although I've tried with a few older versions as well ...
Using IntelliJ 13 ... started a Grails project ... threw together a quick domain class ... using create-domain-class ... defined a few fields and constraints ... then did generate-all ...
Defined the Rest plugin in the BuildConfig with
compile ":rest-client-builder:2.0.0"
also tried with 2.0.1
I am defining the rest bean in the spring/resources.groovy
// Place your Spring DSL code here
beans = {
rest(grails.plugins.rest.client.RestBuilder)
}
Generated a service with create-service ... it's pretty bare-bones
package myPackage
import grails.transaction.Transactional
#Transactional
class myService {
def rest
def serviceMethod() {
def resp = rest.get("http://myServer/myContextRoot/allEmployees")
return resp
}
}
And I am calling this service method from the controller....
def search() {
myService.serviceMethod()
// Not really trying to do anything yet other than see
// if the bean gets injected properly and the method gets called.
render("Not yet implemented")
}
However I always get a Bean Instantiation Exception as the app is trying to start up.
| Running Grails application
| Error 2014-03-06 16:11:02,310 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'rest': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
Message: Error creating bean with name 'rest': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by UnsupportedOperationException: null
->> 186 | put in java.util.AbstractMap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 69 | <init> in grails.plugins.rest.client.RestBuilder
| 57 | <init> . in ''
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run . . in ''
^ 680 | run in java.lang.Thread
Checking the Grails source it seems to be choking on code involved with Proxy intialization, I've attempted to fiddle with the bean instantiation to set proxy settings and it has no affect.
Feel like I must be missing something related to the Plugin configuration, but have been unable to track down the problem. Any constructive input would be most appreciated.
-Jim
The no-arg constructor of RestBuilder creates an immutable map via Collections.emptyMap() on which a put() is later attempted in certain cases (for example, if you have an HTTP proxy defined through your System properties). One workaround is to construct your rest bean using an explicit, mutable Map:
rest(grails.plugins.rest.client.RestBuilder, [:])
I haven't checked to see if this apparent bug has been filed in JIRA. If not, it would probably be worthwhile to create a ticket and attach your sample app.

Resources