JPA replaces "true" by 1 - spring-data-jpa

I use Spring Data JPA with hibernate as persistence provider. PostgreSQL 9.1.5 is my database.
Query:
#Query("select COUNT(u) from User u where u.enabled=true")
is automatically translated to
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=1
As you can see "true" is replaced by "1". Postgre does't accept this query and error is thrown:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=1]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
Query without replacement works fine. In pgadmin query interface the following query works.
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=true
How can I fix this problem?

Make sure you are using correct database dialect in your JPA provider. E.g. in Hibernate it should be:
org.hibernate.dialect.PostgreSQLDialect

Related

SequenceInformation missing

I'm working with a Spring boot Application connecting to an AS400 Database using the com.ibm.db2.jcc.DB2Driver driver with Spring Data JPA.
I use the org.hibernate.dialect.DB2Dialect dialect.
When I start the Application, I get the Error
Could not fetch the SequenceInformation from the database
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=SYSCAT.SEQUENCES;TABLE, DRIVER=4.26.14
Meaning the Table SYSCAT.SEQUENCES is missing, which it is, because it's not needed.
The Application works fine, but the error bothers me.
As far as I see, SequenceInformations are only important when I generate an ID somewhere, what I don't do.
This Application is only used to copy data from one place to another, so I only use JPAs #Id annotation but not the #GeneratedValue one.
Am I missing some use for the SequenceInformation?
Is there some way to turn off the fetching of SequenceInformation?
Those are my application properties:
spring:
datasource:
driver-class-name: com.ibm.db2.jcc.DB2Driver
hikari.connection-test-query: values 1
hikari.maximum-pool-size: 25
jpa:
database-platform: DB2Platform
hibernate.ddl-auto: none
open-in-view: false
properties:
hibernate:
dll-auto: none
dialect: org.hibernate.dialect.DB2Dialect
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
You use the wrong dialect. Please use:
org.hibernate.dialect.DB2400Dialect
I have changed dialect from DB2Dialect to DB2400Dialect and it worked for me.
##spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.DB2Dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.DB2400Dialect

Flyway Issue with DB2

I am using flyway for a deployment and the tables built as a result of flyway are all fine.
The issue I have is with the schema_version table. I am unable to query an individual column in the table. I am only able to perform a select *.
The error message I am getting is:
10:35:49 [SELECT - 0 row(s), 0.000 secs] 1) [Error Code: -206, SQL State: 42703] DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=SCRIPT, DRIVER=4.13.127. 2) [Error Code: -727, SQL State: 56098] DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-206;42703;SCRIPT, DRIVER=4.13.127
Try enclosing the column name in double quotes:
select "SCRIPT" from flyway.schema_version
This might help.
Flyway Schema table is designed to be in lower case.
You can change the table name using below config property.
flyway.table=SCHEMA_VERSION
For more details you can check this
https://flywaydb.org/documentation/faq#case-sensitive
Try to make your query like this:
SELECT "version", "installed_on" FROM "schema_version";

Ecpiselink NativeQuery from other schema

i would execute a simple select with eclipselink from another schema like this:
Query query = em.createNativeQuery("select * from another_schema.TABLE_NAME");
List returnList = query.getResultList();
But when i run my application i get the following error:
java.sql.SQLException: The transaction is no longer active - status: 'Marked rollback.
Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: The transaction is no longer active - status: 'Marked rollback. [Reason=weblogic.transaction.internal.TimedOutException: Transaction timed out after 30 seconds
BEA1-0091256F3B0B87325B62]'. No further JDBC access is allowed within this transaction.
I have privileges to run this sql command, i tried with sql developer, and it's working.
Can anybody please help me, how should I run this NativeQuery?
Thank you!
I solved this error "No further JDBC access is allowed within this transaction." by setting the transaction in Weblogic as "Local Transaction".
Just uncheck the transaction option: Supports Global Transactions

PostgreSQL hangs while executing DDL without log message

I have Postgresql-9.2.10 on CentOS.
I experience the following error:
DETAIL: Multiple failures --- write error might be permanent.
ERROR: could not open file "pg_tblspc / 143862353 / PG_9.2_201204301 / 16439 / 199534370_fsm": No such file or directory
This happens since I stopped the PostgreSQL service, ran pg_resetxlog and started the service. The logs in pg_log look good, and the service is listed without any problem.
DML works well , but not a DDL statement like CREATE TABLE, otherwise an error message is thrown or nothing is visible in the logs in pg_log.
If I try to create a table, there is no reaction, and it looks like the statement is blocked by a lock.
So I tried the following query to look for locks:
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS blocking_statement
FROM pg_catalog.pg_locks blocked_locks
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks
ON blocking_locks.locktype = blocked_locks.locktype
AND blocking_locks.DATABASE IS NOT DISTINCT FROM blocked_locks.DATABASE
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
AND blocking_locks.pid != blocked_locks.pid
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE NOT blocked_locks.granted;
You probably corrupted the PostgreSQL cluster with pg_resetxlog. How exactly did you run the command?
I would restore from the last good backup.

Extracting properties from a Groovy object causes H2 database error

I'm using Grails 2.0, Groovy 1.8.4 on Eclipse STS 3.7. When I execute the following statement to extract properties from a groovy object, Grails throws a SQL exception, not sure why since I'm not using H2 database. I've deleted DataSources.groovy from my project and commented out all references to sql or h2 in other config files, but the problem persists
Note note = [title:'foo', details:'bar']
def objprops = note.properties.findAll{ !['class','metaClass'].contains(it.key)}
The exception...
org.h2.jdbc.JdbcSQLException: Table "NOTE" not found; SQL statement:
select this_.id as id0_0_, this_.version as version0_0_, this_.details as details0_0_, this_.title as title0_0_ from note this_ [42102-147]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.command.Parser.readTableOrView(Parser.java:4562)
at org.h2.command.Parser.readTableFilter(Parser.java:1020)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1622)
at org.h2.command.Parser.parseSelectSimple(Parser.java:1729)