I'm using Eclipse link with JPA 2.1 , noting that I have an Oracle Query use function "INSTR" with the feature of occurrence param.
Is there any equivalent to this method in JPA ?
JPQL supports LOCATE function:
LOCATE
the index of the string within the string, optionally starting at a start index
Related
I have a Spring Boot application with a JpaRepository which contains a native query with this structure:
SELECT a, b, c, CURSOR( SELECT ... FROM ... ), ...
FROM ...
WHERE ...
And I'm getting the following exception:
org.hibernate.MappingException: No Dialect mapping for JDBC type: -10
I am using Oracle12cDialect, and I think the problem comes from the CURSOR in my query, but I don't know how to solve it. Also, I cannot modify the query, I've been ordered to try to implement it as it is.
Thanks in advance for any help.
This SQL returns column of type CURSOR, which is a handle to another SQLs' resultSet. I do not believe SpringBoot support this.
This is a trick how to return data having more than two dimensions.
You have to either use JSON object as 4th column, or use ah-hoc query for each row for 4th column. To query that detail/child object.
We're using testcontainers in integration test with DB. To setup initial state of DB we use container method withInitScript(*pathToScript*). Under the hood it uses org.postgresql.jdbc.PgStatement class to execute query. But an executing fails if sqlQuery contains function/procedure with $$ delimiter. The solution is to replace $$ with ', but it takes long time to control sql sqript and keep in mind necessity of replacing delimiter.
There is related question, but no solution: Exception in JPA when using seed file for PostgreSQL
Is it possible to point a type of delimiter or something like that?
I'm trying to perform the following query:
SELECT p FROM Pessoa p WHERE TRANSLATE(UPPER(p.nome), 'ÂÁÀÄÃÊÉÈËÎÍÌÏÔÓÒÖÕÛÚÙÜÇ', 'AAAAAEEEEIIIIOOOOOUUUUC') LIKE CONCAT('%',TRANSLATE(UPPER(?1), 'ÂÁÀÄÃÊÉÈËÎÍÌÏÔÓÒÖÕÛÚÙÜÇ', 'AAAAAEEEEIIIIOOOOOUUUUC'),'%')
But i realize that hibernate is generating the following final SQL:
... where TRANSLATE(upper(pessoa0_.ds_nome), 'ÂÁÀÄÃÊÉÈËÎÍÌÏÔÓÒÖÕÛÚÙÜÇ', 'AAAAAEEEEIIIIOOOOOUUUUC') like ('%'||TRANSLATE(upper(?)||'ÂÁÀÄÃÊÉÈËÎÍÌÏÔÓÒÖÕÛÚÙÜÇ'||'AAAAAEEEEIIIIOOOOOUUUUC')||'%')...
Note that the commas inside the TRANSLATE function were replaced by || which leads to an org.postgresql.util.PSQLException: ERROR: function translate(text) does not exist
What am I doing wrong?
Spring: 4.3.4.RELEASE
Spring data: spring-data-jpa:1.10.5.RELEASE
Hibernate is not simply replacing commas. It is converting a JPQL (or possibly HQL) query int SQL. The double pipes || are a common SQL syntax for the JPQL CONCAT function.
If it doesn't work for your Postgres DB you are probably using the wrong dialect. Configure Hibernate to use the correct Dialect for your database.
See for example this article for how to do that.
I have a query starting with REPLACE. When I use it directly in MySQL console everything is fine, so query is ok. However, when I put it in my code like this:
#Query("REPLACE INTO WeekAggregate...
There is an error:
web - 2016-10-05 10:35:44,297 [localhost-startStop-1] ERROR o.h.hql.internal.ast.ErrorCounter - line 1:1: unexpected token: REPLACE
antlr.NoViableAltException: unexpected token: REPLACE
How could I fix this? Is REPLACE not supported in HQL?
HQL is trasversal to underlying DBMS. So some functions you're using in your SQL can't be interpretated by HQL.
You have two ways:
change your HQL query (in this case you can rewrite your query with an DELETE/INSERT statement)
you can write your query in SQL and you can use a method createSqlQuery so the interpreter, runs the query as SQL native query.
I changed my query to native SQL query by using nativeQuery = true flag.
Grails in memory H2 DB is not supporting to_date function..
so the suggestion I got by going through the forums is using 'EXTRACT' function.
But not sure how to replace the following to_Date with Extract.
to_date(currentDate,YYYY_MM_DD HH:MM.ss)..
Extract -?
You could either:
Use the built-in function parsedatetime(dateAsString, formatString)
Create a user defined function