I have an API in spring boot using hibernate.
Initially, the database to request was Hive, it's now Kudu throw Impala.
I followed recommendations and set the dialect to org.hibernate.dialect.HSQLDialect.
The classical requests work fine excepting the Page<T> findAll(#Nullable Specification<T> var1, Pageable var2) from org.springframework.data.jpa.repository
when I paginate (page > 0) and so I have the exception:
[Cloudera]ImpalaJDBCDriver ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:ParseException: Syntax error in line 1:
select limit 10 10 qualityres0_.id ...
^
Encountered: LIMIT
Expected: ALL, CASE, CAST, DATE, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, STRAIGHT_JOIN, TRUNCATE, TRUE, IDENTIFIER
Spring boot version: 2.3.4.RELEASE
Impala jdbc driver: com.cloudera.impala.jdbc ImpalaJDBC41 v2.6.15.1017
Finally it works fine with org.hibernate.dialect.SQLServerDialect
Related
We are using spring-boot with spring-boot-starter-jooq. For some complex checks of constraints triggers are used which raise error with specific message. The exception is caught on persistence layer and converted into business exception.
The behavior has been changed in last spring boot versions 2.4.x. For example hsqldb with scherma:
CREATE TABLE tab1 (
K INT PRIMARY KEY
)^;
CREATE TRIGGER trig1 BEFORE INSERT ON tab1
BEGIN ATOMIC
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'some error';
END^;
and the code for insert into table:
#Transactional
public void withTriggerException() {
create.insertInto(DSL.table("tab1"))
.set(DSL.field("k"), 1)
.execute();
}
The type and the message of thrown exception differs from spring-boot version.
2.3.6, 2.3.9
org.springframework.jdbc.UncategorizedSQLException: jOOQ; uncategorized SQLException for SQL [insert into tab1 (k) values (cast(? as int))]; SQL state [45000]; error code [5800]; some error; nested exception is java.sql.SQLException: some error
2.4.0, 2.4.1, 2.4.2
java.lang.NullPointerException: null
2.4.3
org.jooq.exception.DataAccessException: SQL [insert into tab1 (k) values (?)]; Unspecified RuntimeException
at org.jooq_3.14.7.HSQLDB.debug(Unknown Source) ~[na:na]
at org.jooq.impl.Tools.translate(Tools.java:2892) ~[jooq-3.14.7.jar:na]
at org.jooq.impl.DefaultExecuteContext.exception(DefaultExecuteContext.java:730) ~[jooq-3.14.7.jar:na]
at org.springframework.boot.autoconfigure.jooq.JooqExceptionTranslator.handle(JooqExceptionTranslator.java:83) ~[spring-boot-autoconfigure-2.4.3.jar:2.4.3]
at org.springframework.boot.autoconfigure.jooq.JooqExceptionTranslator.exception(JooqExceptionTranslator.java:55) ~[spring-boot-autoconfigure-2.4.3.jar:2.4.3]
at org.jooq.impl.ExecuteListeners.exception(ExecuteListeners.java:274) ~[jooq-3.14.7.jar:na]
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:390) ~[jooq-3.14.7.jar:na]
at org.jooq.impl.AbstractDelegatingQuery.execute(AbstractDelegatingQuery.java:119) ~[jooq-3.14.7.jar:na]
at com.example.demo.FooDAO.withTriggerException(DemoApplication.java:38) ~[classes/:na]
...
The behavior has been reproduced on hsqldb but is same on PostgreSQL. Another errors (duplicate key, foreign keys, etc.) are working as expected.
It is possible to obtain error message ("some error" in example) from trigger with spring-boot 2.4.x?
You probably ran into this issue:
https://github.com/jOOQ/jOOQ/issues/11304, which has been fixed in jOOQ 3.14.6 and 3.15.0.
Some background on the incompatible change in Spring that produced this NPE regression in jOOQ can be seen here:
https://github.com/spring-projects/spring-framework/issues/24064
The fix should be available in Spring Boot 2.5.0 and 2.4.3:
https://github.com/spring-projects/spring-boot/issues/25214
https://github.com/spring-projects/spring-boot/issues/25240
You should be able to access the JDBC SQLException from jOOQ's DataAccessException using DataAccessException.getCause(Class), e.g.
exception.getCause(SQLException.class);
But there's probably a better way to have the Spring exception translator provide you with the actual cause directly.
I'm trying to write some tests for my java application and my entity persistence uses oracle's sys_guid() for primary key.
Everything works fine when connected to oracle, but when I use H2 in memory for my testing, the following statement used to generate the primary guid value as a char(32) returns a much bigger string (144).
select rawtohex(sys_guid()) from dual
Is there an extra configuration to correctly setup oracle mode or is this somehow a bug
I'm using springboot with spring-data and hibernate to handle database comunication, here is a sample method that generates the guid.
#Repository
public interface TokenRecuperacaoSenhaRepository extends ExtendedSpringRepo<TokenRecuperacaoSenha, String>
{
#Query(value = "select rawtohex(sys_guid()) from dual", nativeQuery = true)
public String genereateToken();
}
When connected to Oracle, returns "8E0FFC48082AB39FE0539BD3E10AC537"
While with H2, returns "00660032003300620037003000360065002d0031006400630066002d0034003700620030002d0039003400360066002d006100620065003400320034006400360030006300360038"
I'm guessing there is some conversion issue with the functions used.
Both SYS_GUID() and RAWTOHEX() functions are non-standard and aren't fully compatible between Oracle and H2.
This incompatibility was fixed in Oracle compatibility mode of H2, so if you can build H2 from its current sources you will be able to use these functions in this compatibility mode.
You can get the sources from the GitHub:
https://github.com/h2database/h2database
Building instructions are here:
https://h2database.com/html/build.html#building
You need the jar target.
Don't forget to set the compatibility mode by appending ;MODE=Oracle to your connection URL or by using SET MODE Oracle; command.
If you cannot use an own build of H2 you need an alternative method for H2 that will use something like SELECT CAST(CAST(UUID() AS BINARY) AS VARCHAR)
I am using Spring 4.x and hibernate 5.x with SQLServer. I have a requirement to paginate data returned by a nativequery. I'm doing it like this:
#Query(value="select * from X where y=?1 \n#pageable\n",
countQuery="select count(*) from X where y=?1 \n#pageable\n",nativeQuery=true)
List<Object[]> XXX(Integer userId, Pageable pageable);
It's throwing me com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '#pageable'. If I don't use \n#pageable\n then it gives me compile time error that #pageable can't be used with native query. Please help if anyone faced similar issue
DBMS - oracle 11gr2
we recently upgraded the IDE and OS of a java console application that runs 10 times a month.
now None of our queries work properly since hibernate converts the letter i to İ which is not I. All insert statements and id fields affected negatively.
now in our queries
id -> İD not ID
insert -> İNSERT not INSERT
neither select statements nor inserts do not execute.
for example:
in the previous version Select id from table a is now sent to the db as
SELECT İD from table a ,
and we dont have such a column called İD at all.
stack trace is as follows
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00904: "İD": geçersiz belirleyici (invalid identifier)
Query: ReadObjectQuery(name="readObject" referenceClass=OrtakEntity sql="SELECT İD, ADİ, ALACAKLARİNDAHACİZVARMİ, ANNEADİ, FROM A WHERE (İD = ?)")
********************sistem toplam sure***********************0.0
********************Time unit toplam sure***********************0
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00904: "İD": geçersiz belirleyici
Error Code: 904
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:526)
at org.eclipse.persistence.internal.session
I resolved the issue by changing the settings of the computer to English and United States as location. (still not the best approach but now the program runs)
I am using embedded HSQLDB in my JUnits. It is throwing
SQL state [3F000]; error code [-4850]; invalid schema name:info
when it executes query following query
select db.id, db.name,info.desc from user_db db,user_info info where db.user_id = info.user_id and info.active = 'Y' and db.dept = info.dept(+)
the above query runs fine in oracle but not in embedded HSQLDB
please let me know what is wrong in this.