JPA & Hibernate application uses HSQLDB for JUnit tests.
HSQLDB 1.8.0
Hibernate 3.2.4.sp1
Java 7
While the tests worked fine against an Oracle database, getting the following error now that we are using MSSQL 2016:
Unexpected token: GETDATE in statement [select ..... effective_date < GETDATE() AND ... ]
So I understand that HSQL uses SYSDATE, CURDATE, or NOW instead of the MSSQL GETDATE function, and I've done the following:
Attempted to set sql.syntax_mss to true by URL and SQL statement:
public static final String HYPERSONIC_JDBC_URL = "jdbc:hsqldb:mem:aname;sql.syntax_mss=true";
entityManager.createNativeQuery("set database sql syntax MSS true").executeUpdate();
Register the function in the Dialect and/or create a function:
registerFunction("GETDATE", new NoArgSQLFunction("SYSDATE", new DateType()));
entityManager.createNativeQuery("CREATE FUNCTION GETDATE() RETURNS DATE RETURN CURDATE()").executeUpdate();
None of this seems to have any effect.
Live application is connected to MS SQL Server 2016 via mssql-jdbc-6.2.1.jre7 driver.
So while upgrading the libraries as #fredt mentioned in the comments is probably the best route, upgrading hsqldb.jar breaks dbunit.jar, upgrading that breaks.. etc.
Was able to remove the GETDATE occurrences and fix the sequence generation strings (select next value for seq_name from seq_name is the format it likes) and now we are back to a working state.
Upgrading these libraries can be put in the bucket with upgrading jBoss, Hiberate, jBPM and Quartz :)
Related
I am using Jooq version 3.16.6 with Java 11 and Spring Boot 2.6.6 and (PostgreSQL) 14.1
The issue i am having is with multiset , the non multiset query using the old join method works fine . However when using multiset and examining the sql i can see the word multiset actually in the sql query hence it thorws a syntax error
var result =
dslContext.select(USERS.FIRST_NAME,USER_LEVELS.USER_LEVEL_NAME)
.from(USERS)
.join(USER_LEVELS)
.on(USERS.USER_LEVEL_ID.eq(USER_LEVELS.USER_LEVEL_ID))
.where(USERS.USERNAME.eq("email#email.com"))
.fetch();
The above is the standard join method works fine
The below is the multiset version
var result =
dslContext.select(USERS.FIRST_NAME,
multiset(select(USER_LEVELS.USER_LEVEL_NAME)
.from(USER_LEVELS)
.where(USER_LEVELS.USER_LEVEL_ID.eq(USERS.USER_LEVEL_ID)))
)
.from(USERS)
.where(USERS.USERNAME.eq("email#email.com"))
.getSQL();
I am using the getSQL to see the sql it is running which comes out as below
select "public"."users"."first_name",
multiset(select "public"."user_levels"."user_level_name"
from "public"."user_levels" where "public"."user_levels"."user_level_id" = "public"."users"."user_level_id") from "public"."users" where "public"."users"."username" = ?
The issue is obviously the multiset being in the sql which causes a syntax error.
I am at a loss as to why this is , unless its some setting for my postgres (which i don't think)
Any ideas ?
You probably haven't configured your SQLDialect correctly, e.g.
spring.jooq.sql-dialect=Postgres
See also: Spring Boot JOOQ sql dialect not picked up from application.properties
I'm developing a Java PLSQL procedure that must instanciate a CLOB object. In order to instanciate that Clob object I must use a connection object. Based on Oracle documentation, I can get the current connection using java.sql.DriverManager however when I execute the following code an AbstractMethodError error is thrown
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
Clob clob = conn.createClob();
I see a lot of posts talking about driver compatibility with Java runtime running the code but as I am working inside an Oracle DB I suppose it should be compatible.
Oracle version: 11.2.0.4.0
My goal is to create a clob inside my java method and return it to my plsql code. How can I instanciate a Clob inside a java class stored inside an Oracle database ?
Thanks for any help !
The creation of the CLOBusing conn.createClob() works for my fine in 12c. I suspect from your error message in 11 you'll have to use the CLOB.createTemporary method to create the CLOB (which works fine in 12c as well but is marked as deprecated).
Here an example
Java class
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "CreateCLOB"
AS
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.*;
/****** START PASTE JAVA CLASS HERE *****/
public class CreateCLOB{
public static void ClobProc (Clob cl[]) throws SQLException
{
Connection conn = DriverManager.getConnection ("jdbc:default:connection:"); /* or use "jdbc:oracle:kprb:" */
Clob clob = CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_SESSION); /* this is deprecated in 12c */
// conn.createClob(); /* works fine in 12.1.0.2.0 */
clob.setString(1, "Test Data");
cl[0] = clob;
}
}
/
Wrapper
create or replace procedure MyClob (cl OUT Clob)
as language java
name 'CreateCLOB.ClobProc(java.sql.Clob[])';
/
Test
declare
x Clob;
begin
MyClob(x);
dbms_output.put_line('created CLOB length = ' || dbms_lob.getlength(x));
end;
/
created CLOB length = 9
As mentioned I can't test it on version 11, but I suppose it will work.
select * from v$version;
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
You need to follow these steps:
1. On your computer you should have an Oracle jdbc driver (http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html)
2. Load a driver
Class.forName("oracle.jdbc.driver.OracleDriver");
3. Get a connection
Connection connection =
DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:SID","username","password");
UPDATE: If you work inside of Oracle DB, you can choose a type of driver (Server-Side Thin Driver or Server-Side Internal Driver) - https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html
Even when you are not using the createClob() you may get this error when starting the application if you are using an older version of hibernate core library.
The errors is just thrown, but the application starts. If you are not worried about it you may leave it, but if you don't want to see an error during application startup then her is the fix.
Its a bug in the Spring boot 2.X - hibernate core 5.3.X combination. There are 2 solutions for the issue. I would suggest #1.
Upgrade all hibernate libraries to 5.4.X (my way)
Provide spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true in your application properties/ yml file.(If you really do not want to upgrade your hibernate core library).
I have got this when upgrading spring boot to 2.4 and using Teradata DB without any createClob().
If you still want to know how the error is being created, its well explained in https://alexpask.com/spring-boot-createclob-error/
Hello all I have a query in my code which is working with oracle 12c.
SELECT *
FROM TABLE-A
join TABLE-B on TABLE-A.id=TABLE-B.id
where TABLE_B.ISRT_TS BETWEEN TO_TIMESTAMP ('10-JUN-17 04.00.00.000000000 AM','DD-Mon-RR HH:MI:SS.FF9 AM') AND TO_TIMESTAMP('10-Sep-17 03.59.59.999999999 AM', 'DD-Mon-RR HH:MI:SS.FF9 AM')
but when I execute same query in HSQL I am getting exception. can any one suggest what to change in the existing query to work in oracle and hsql.
Error in hsql:data exception: invalid datetime format: 9 AM
Elapsed Time: 0 hr, 0 min, 0 sec, 0 ms.
HQL vesrsion: 1.8.0.10
to_timstamp() is not part of the SQL standard, so it's not a surprise that HSQL does not understand it.
A portable way of writing your condition is to use ANSI timstamp literals:
select *
from table_a
join table_b on table_a.id = table_b.id
where table_b.isrt_ts between timestamp '2017-06-10 04:00:00' and timestamp '2017-09-10 03:59:59.99999'
I don't know if the ancient and outdated version 1.8 supports that - but you should really upgrade to a current version.
When running the following query on an Informix database, the database reports a general syntax error (without any indication with respect to what causes the problem). The same query runs perfectly on CUBRID or Oracle databases, both of which also support the CONNECT BY syntax:
select
lower(connect_by_root "t_directory"."name"),
connect_by_isleaf,
connect_by_iscycle,
substr(
sys_connect_by_path(lower("t_directory"."name"), '/'),
2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc
The database I'm using is a Developer Edition of Informix 12.10 on Windows. I'm running the query from a JDBC driver with the following connection URL (to allow for quoted table identifiers):
jdbc:informix-sqli://localhost:9092/test:INFORMIXSERVER=ol_informix;DELIMIDENT=y
The exact issue here is the fact that prior doesn't accept quoted table identifiers, although quoted column identifiers seem to be fine. This query runs perfectly well:
select
lower(connect_by_root "t_directory"."name"),
connect_by_isleaf,
connect_by_iscycle,
substr(
sys_connect_by_path(lower("t_directory"."name"), '/'),
2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc
... with the difference being:
-- Bad:
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"
-- Good:
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
We are using ojdbc14_10.1.0.2.jar with a Java/J2EE application (that use directly JDBC) and JDK5, but when we tried to migrate into ojdbc5-11.2.0.3.jar we encountered an issue related to some sql request (jdbc) that doesn't work anymore.
The pseudo SQL request is :
select *
from quotas q
where q.datdeb<='2013-09-05' and q.datfin>='2013-09-05'
and q.datdeb is not null and q.datfin is not null order by ....;
The NLS parameters for date is :
DD/MM/RR
Which is not compatible with the date format giving as parameter in the request.
Everything worked fine when we were using ojdbc14; apparently it does an implicite conversion for the date.
For information, The oracle Database is 11g Release 11.2.0.3.0 - 64bit
Best regards.
I believe you just need to use the to_date function with an appropriate date mask to get around the problem.
select *
from quotas q
where q.datdeb<=to_date('2013-09-05','yyyy-mm-dd') and q.datfin>=to_date('2013-09-05', 'yyyy-mm-dd')
and q.datdeb is not null and q.datfin is not null order by ....;