I am creating a spring-batch application which reads from a CSV file and writes into a DB2 database.
Spring-boot version : 2.0.5.RELEASE
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>db2jcc4</version>
</dependency>
I am getting an BadSqlGrammarException when Spring Batch tries to insert into the BATCH_JOB_EXECUTION table.
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT into BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703,
SQLERRMC=JOB_CONFIGURATION_LOCATION, DRIVER=4.26.14Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT into BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=JOB_CONFIGURATION_LOCATION, DRIVER=4.26.14
Thanks in advance for any kind of support and direction that helps in resolving this issue.
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=JOB_CONFIGURATION_LOCATION
From this, SQLSTATE 42703 means An undefined column or parameter name was detected . So it is most probably due to the BATCH_JOB_EXECUTION does not have JOB_CONFIGURATION_LOCATION column.
Make sure your batch related tables have the schema that are the same as this.
Related
I am trying to perform a basic connection between to a local postgresql DB from a very basic SpringBootProject (for training purpose).
# configure postgresql
spring.datasource.platform=postgres
spring.datasource.jdbc-url=jdbc:postgresql://localhost:5432/db
spring.datasource.username=postgres
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.hibernate.ddl-auto=none
So far, I have managed to have it compile and run... but when I am trying to access my DB, I get a "Table "FILMS" not found" error (org.h2.jdbc.JdbcSQLException). When I insert data from a data.sql, I get the inserted movies. But without this initializer, I cannot get data from my db...
Table "FILMS" not found; SQL statement:
select film0_.code as
code1_0_, film0_.date_prod as date_pro2_0_, film0_.did as did3_0_,
film0_.kind as kind4_0_, film0_.title as title5_0_ from films film0_
[42102-197]
2018-07-26 12:24:18.151 ERROR 10376 --- [nio-9000-exec-1]
o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for
servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessResourceUsageException: could
not prepare statement; SQL [select film0_.code as code1_0_,
film0_.date_prod as date_pro2_0_, film0_.did as did3_0_, film0_.kind
as kind4_0_, film0_.title as title5_0_ from films film0_]; nested
exception is org.hibernate.exception.SQLGrammarException: could not
prepare statement] with root cause
org.h2.jdbc.JdbcSQLException: Table "FILMS" non trouvée
Spring boot is in version 2.03 RELEASE; both postgresql connector AND server's ones are 9.4.
I am using spring boot parent starter, as well as data-jpa-starter (with no extra hibernate/jpa depencies defined).
The source code is here
My postresql server is up, the database "db" exists, and its table public."FILMS" is full of data...
Any idea on what I am doing (or undestanding) wrong?
In your application properties file try
spring.jpa.hibernate.ddl-auto=validate
It will try to check the table in your db
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by JOB_INSTANCE_ID desc]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
I guess you may need to edit you xml config file
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"
p:tablePrefix="MYDB.BATCH_"/>
MYDB been your schema
Source
I have created a HSQLDB (version 2.3.3) database preloaded with data and bundled it up as a resource (db.properties and db.script) to be used by automated tests where I do not need the data generated by the tests to be saved back to disk. This works fine for most of the JPA entities I have (all CRUD operations work as expected). However, I have two entities that include a column annotated with '#Lob' where I cannot create new entities because HSQLDB fails saying 'the table data is read only'.
I've read through the documentation about Large Objects but it doesn't describe the behaviour when using a resource database. I'm guessing HSQLDB is trying to create 'db.lobs' but it can't because effectively files_readonly=true.
Does anyone know if it is possible to create an entity with a 'large object' column with a HSQLDB resource database?
The stack trace is:
WARN 12-09-2016 00:57:26 - SQL Error: -458, SQLState: S1000
ERROR 12-09-2016 00:57:26 - org.hsqldb.HsqlException: The table data is read only
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1338)
..app classes...
Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1335)
... 29 more
Caused by: java.sql.SQLException: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
... 39 more
Caused by: org.hsqldb.HsqlException: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SessionData.allocateLobForResult(Unknown Source)
at org.hsqldb.Session.allocateResultLob(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.performPreExecute(Unknown Source)
... 43 more
Caused by: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.persist.LobManager.setCharsForNewClob(Unknown Source)
... 46 more
java.lang.RuntimeException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
The code I am running looks like this:
#Test
public void testCreateUserSettings() throws Exception {
MyDatabase db = MyDatabaseFactory.createMyDatabase("jdbc:hsqldb:mem:db1;sql.syntax_ora=true", new Properties());
//MyDatabase db = MyDatabaseFactory.getMyDatabase("jdbc:hsqldb:res:/my-db-base");
Properties properties = new Properties();
properties.putAll(db.getConnectionProperties());
properties.setProperty("javax.persistence.provider", "org.hibernate.jpa.HibernatePersistenceProvider");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("InMemorySeederPU", properties);
EntityManager em = emf.createEntityManager();
try {
Date now = new Date();
String defaultData = "{\"key\": \"value\"}";
String defaultId = UUID.randomUUID().toString();
String userId = "uA1";
UserSetting setting = new UserSetting();
setting.setIdObject(defaultId);
setting.setDateCreate(now);
setting.setDateUpdate(now);
setting.setDateArrive(now);
setting.setIdDatabase("A");
setting.setIdUserCreate(userId);
setting.setIdUserUpdate(userId);
setting.setIdOwner(userId);
setting.setNamespace(defaultId);
setting.setEntityVersion(1L);
setting.setData(defaultData);
setting.setEtag(DigestUtils.md5Hex(defaultData));
em.getTransaction().begin();
em.persist(setting);
em.flush();
em.getTransaction().commit();
UserSetting setting2 = em.find(UserSetting.class, defaultId);
Assert.assertEquals(setting2, setting);
}
finally {
em.close();
}
}
MyDatabase is just a wrapper to get a connection to a database. If I use 'jdbc:hsqldb:mem:...' the test works fine (the createMyDatabase() method loads the in-memory database with the data I need). However, if I replace that with the commented-out line that uses 'jdbc:hsqldb:res:...' then the test fails and HSQLDB reports the exception 'The table data is read only'.
Putting Hibernate into DEBUG mode shows the following:
DEBUG 12-09-2016 16:46:22 - Initializing EntityManagerFactoryRegistry : org.hibernate.jpa.internal.EntityManagerFactoryRegistry#59ce792e
DEBUG 12-09-2016 16:46:22 - Registering EntityManagerFactory: InMemorySeederPU
DEBUG 12-09-2016 16:46:23 - begin
DEBUG 12-09-2016 16:46:23 - Obtaining JDBC connection
DEBUG 12-09-2016 16:46:23 - Obtained JDBC connection
DEBUG 12-09-2016 16:46:23 - initial autocommit status: false
DEBUG 12-09-2016 16:46:23 - Generated identifier: d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, using strategy: org.hibernate.id.Assigned
DEBUG 12-09-2016 16:46:23 - Processing flush-time cascades
DEBUG 12-09-2016 16:46:23 - Dirty checking collections
DEBUG 12-09-2016 16:46:23 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
DEBUG 12-09-2016 16:46:23 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG 12-09-2016 16:46:23 - Listing entities:
DEBUG 12-09-2016 16:46:23 - com.ben.entity.UserSetting{data={"key": "value"}, dateArrive=Mon Sep 12 16:46:23 AEST 2016, idDatabase=A, idObject=d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, idUserDelete=null, dateCreate=Mon Sep 12 16:46:23 AEST 2016, entityVersion=1, dateUpdate=Mon Sep 12 16:46:23 AEST 2016, idUserCreate=uA1, namespace=d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, etag=88bac95f31528d13a072c05f2a1cf371, idUserUpdate=uA1, idOwner=uA1, dateDelete=null}
DEBUG 12-09-2016 16:46:23 - insert into user_settings (data, date_arrive, date_create, date_delete, date_update, entity_version, etag, id_database, id_owner, id_user_create, id_user_delete, id_user_update, namespace, id_object) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
DEBUG 12-09-2016 16:46:23 - could not execute statement [n/a]
java.sql.SQLException: org.hsqldb.HsqlException: The table data is read only
Thanks in advance,
Ben
According to the HSQLDB manual,
A res: catalog consists of the files for a small, read-only database
that can be stored inside a Java resource such as a ZIP or JAR archive
and distributed as part of a Java application program.
Consequently you cannot insert data into such a database, and the exception is expected
From the section RES and Files Readonly Databases:
There is another option which allows MEMORY tables to be writeable, but without persisting the changes at SHUTDOWN. This option is activated with the property, value pair, files_readonly=true, which can be added to the .properties file of the database, or included in the URL of the first connection to the database.
A res: catalog, is a set of database files on the classpath (inside a
jar or alongside class files). The database is opened with a URL in
the form of jdbc:hsqldb:res:. These databases are
always files_readonly and have the same restrictions as files_readonly
file: catalogs.
CACHED tables and LOBS in these catalogs are readonly. It is not
possible to create new LOBs in these catalogs, but you can use
existing LOBs in new rows.
I am using Eclipselink 2.5.1 and I have the problem that no table update take place when I run Project->JPA Tools->Create tables form Entites... although I have
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
in my peristence.xml (with generation output mode = database).
I have an already existing database table addresses created from a JpaEntity Address.
After table creation I wanted to add a further column named addressType which is of type AddressType which is an enum.
In my JpaEntity Address Eclipse is grumbling that addressType column can not be found in table addresses.
Re-running table creation from entities does not what I want. The column will not be added to the existing table structure. what am I missing to do?
Running Project->JPA Tools->Create tables from Entities... gives the following output:
[EL Config]: metadata: The alias name for the entity class [class com.tsystems.ikt.service.jpaParking.model.Address] is being defaulted to: Address.
[EL Config]: metadata: The column name for element [region] is being defaulted to: REGION.
[EL Config]: metadata: The column name for element [street] is being defaulted to: STREET.
[EL Config]: metadata: The column name for element [zipCode] is being defaulted to: ZIPCODE.
[EL Config]: metadata: The column name for element [streetNumber] is being defaulted to: STREETNUMBER.
[EL Config]: metadata: The column name for element [addressType] is being defaulted to: ADDRESSTYPE.
[EL Config]: metadata: The column name for element [addressId] is being defaulted to: ADDRESSID.
[EL Config]: metadata: The column name for element [city] is being defaulted to: CITY.
[EL Config]: metadata: The column name for element [country] is being defaulted to: COUNTRY.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5
[EL Fine]: connection: Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE entrances
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--DROP TABLE addresses
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error Code: 1217
Call: DROP TABLE addresses
Query: DataModifyQuery(sql="DROP TABLE addresses")
[EL Fine]: sql: Connection(1483721814)--CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))
[EL Fine]: sql: SELECT 1
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'addresses' already exists
Error Code: 1050
Call: CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))
Query: DataModifyQuery(sql="CREATE TABLE addresses (ADDRESSID INTEGER NOT NULL UNIQUE, ADDRESSTYPE VARCHAR(50), CITY VARCHAR(50) NOT NULL, COUNTRY VARCHAR(50) NOT NULL, REGION VARCHAR(50) NOT NULL, STREET VARCHAR(100) NOT NULL, STREETNUMBER VARCHAR(10) NOT NULL, ZIPCODE VARCHAR(15) NOT NULL, PRIMARY KEY (ADDRESSID))")
Why does Eclipselinkt try to drop and re-create the table addresses although I said create-or-extend-tables?
"eclipselink.ddl-generation" is an EclipseLink runtime property that is looked at when you deploy your peristence unit, but you are not running/deploying your persistence unit. Instead you are executing an Eclipse command to create tables from your entities. Eclipse uses EclipseLink under the covers, but will pass in its own properties to be sure your tables get created on the database it is pointed at. This the settings are described here:
https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks007.htm
If you want to have EclipseLink extend your tables, just run your app.
I have a problem to use PostgreSQL with JPA.
When i try to execute my app on glassfish i got this error:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: no schema has been selected to create in
Error Code: 0
Call: CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:895)
So how can i specify the schema for JPA so it can be able to use postgresql
note: i have added the postgresql maven dependancy:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
Please help me; Thank you
The schema is specified with the "search_path" variable in postgres.
To solve your problem, you have 2 solutions:
Permanently add the search to the user used by your connection:
ALTER user username set search_path=yourschema ;
Add temporarly the search_path in the jdbc connection (which i find ugly)
set search_path=yourschema;