Unable to create initial connections of pool when start up Grails app - oracle

I am using Oracle 11g. And have the following error when starting up my Grails app in development mode. My DataSource.Groovy is listed below. Please advise.
Error |
2014-12-25 18:42:11,836 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initia
l connections of pool.
Message: oracle.jdbc.driver.OracleDriver
dataSource {
pooled = true
jmxExport = true
driverClassName = "oracle.jdbc.driver.OracleDriver"
username = "john"
password = "password"
}
Update:
I had the following line in Build.Groovy. But the app failed to start. So I deleted it. Do I still need a plugin? If so, what should it be?
runtime ":com.oracle:ojdbc6:11.2.0.1.0"
Update -2
Afte I run grails compile --refresh-dependencies and start up the app, now I have the following error.
Error |
2014-12-25 19:30:22,069 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error i
nitializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initia
lization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFacto
ry' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.fact
ory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference
to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframewo
rk.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve r
eference to bean 'dataSourceLazy' while setting constructor argument; nested exception is org.spring
framework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceLazy': Canno
t resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested excepti
on is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSo
urceUnproxied': Error setting property values; nested exception is org.springframework.beans.Propert
yBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean fai
led; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bea
n with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting be
an property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce
ption: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource'
while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.Bea
nCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'da
taSourceLazy' while setting constructor argument; nested exception is org.springframework.beans.fact
ory.BeanCreationException: Error creating bean with name 'dataSourceLazy': Cannot resolve reference
to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springfram
ework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Erro
r setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateExceptio
n; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve
reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFact
ory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'dataSource': Cannot resolve reference to bean 'dataSourceLazy' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean wi
th name 'dataSourceLazy': Cannot resolve reference to bean 'dataSourceUnproxied' while setting const
ructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is or
g.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve refe
rence to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springf
ramework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot res
olve reference to bean 'dataSourceLazy' while setting constructor argument; nested exception is org.
springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceLazy':
Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested e
xception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '
dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.P
ropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve referenc
e to bean 'dataSourceLazy' while setting constructor argument; nested exception is org.springframewo
rk.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceLazy': Cannot resol
ve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is o
rg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnp
roxied': Error setting property values; nested exception is org.springframework.beans.PropertyBatchU
pdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dataSourceLazy': Cannot resolve refe
rence to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.spri
ngframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied'
: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateEx
ception; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting
property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClas
sName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC dri
ver class [oracle.jdbc.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by PropertyBatchUpdateException: Failed properties: Property 'driverClassName' threw exceptio
n; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdb
c.driver.OracleDriver]
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
| Error Forked Grails VM exited with error

The Oracle jar with the JDBC driver is not found. Put the file in the lib dir of your grails project.
When you put a jar file in the lib directory, it is not auto-discovered. Run
grails compile --refresh-dependencies
and that will get Grails to find the jar and add it to the dependencies and classpath.

Related

Spring session table not created in Docker container

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.

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

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.

Could not synchronize database state with session Error in Grails Hibernate

I have registered a MySecurityEventListener in my Grails app to set a login count after a user has been logged in.
MySecurityEventListener class:
class MySecurityEventListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent>, LogoutHandler {
/**
* Handler for after login.
*/
#Override
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
User.withNewSession {
User user = User.get(event.authentication.principal.id)
user.lastLoginDate = new Date() // set the last login date
user.loginCount += 1 // increase the login count
user.isLoggedIn = true
user.save(flush: true)
}
}
/**
* Handler for after logout.
*/
#Override
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
User.withNewSession {
User user = User.get(authentication.principal.id)
user.isLoggedIn = false
user.save(flush: true)
}
}
}
Sometimes when a user loggs in I get the following error:
| Error 2013-07-03 13:40:56,306 [http-nio-8080-exec-1]
ERROR events.PatchedDefaultFlushEventListener -
Could not synchronize database state with session Message:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
Line | Method
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
2013-07-03 13:40:56,551 [http-nio-8080-exec-1] INFO cpr.SessionSupport - Session created
2013-07-03 13:40:56,554 [http-nio-8080-exec-2] INFO cpr.SessionSupport - Session created
| Error 2013-07-03 13:40:56,554 [http-nio-8080-exec-1] ERROR [/demo].[gsp] - Servlet.service() for servlet [gsp] in context with path [/demo] threw exception
Message: Object of class [demo.User] with identifier [ffd93c5639b54405bf]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
Line | Method
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
Caused by StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [demo.User#ffd93c5639b54405bf]
->> 38 | doCall in demo.MySecurityEventListener$_onApplicationEvent_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 33 | onApplicationEvent in demo.MySecurityEventListener
| 1145 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
How do I have to fix this error?
withTransaction provides access to the underlying transaction. If needed a control over transaction rollback you can use it.
withSession uses the default session provided by SessionFactory. If needed a control over sesion then use it.
Looking at your example, I would vouch for withTransaction (the simplest one).

Grails 2.0.1 : async messaging: `jmsConnectionFactory` compilation error

I have resource.groovy
beans = {
jmsConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) { brokerURL = 'vm://localhost' }
}
and on run it says
Running Grails application
| Error 2012-02-24 18:02:13,490 [pool-6-thread-1] ERROR spring.GrailsRuntimeConfigurator - [RuntimeConfiguration] Unable to load beans from resources.groovy
Message: No such property: org for class: resources
Line | Method
->> 3 | doCall in resources$_run_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 736 | invokeBeanDefiningClosure in grails.spring.BeanBuilder
| 569 | beans . . . . . . . . . . in ''
| 736 | invokeBeanDefiningClosure in ''
| 569 | beans . . . . . . . . . . in ''
| 511 | invokeMethod in ''
| 303 | innerRun . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . . . . . . . . . . in java.lang.Thread
| Error 2012-02-24 18:02:16,537 [pool-6-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'delayedCreateMessageJmsListenerContainer': Cannot resolve reference to bean 'jmsConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jmsConnectionFactory' is defined
Message: Error creating bean with name 'delayedCreateMessageJmsListenerContainer': Cannot resolve reference to bean 'jmsConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jmsConnectionFactory' is defined
It worked all well before upgrade, after updating to 2.0.1 it failed with this error, I am using groovy compiler 1.8.6
I have always configured ActiveMQ in Grails as follows:
BuildConfig.groovy
dependencies {
compile 'org.apache.activemq:activemq-core:5.5.0'
}
resources.groovy
import org.springframework.jms.connection.SingleConnectionFactory
import org.apache.activemq.ActiveMQConnectionFactory
beans = {
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = { ActiveMQConnectionFactory cf ->
brokerURL = 'vm://localhost'
}
}
}
It may be a ClassNotFound error in disguise. Try adding an import statement:
import org.apache.activemq.ActiveMQConnectionFactory
and see if you get a ClassNotFoundError, if so then it's just a matter of tracking down the missing dependency.

Resources