SQLGrammar Exception in integration tests on H2 Database - oracle

#Query(nativeQuery = true, value = "SELECT *\n" +
"FROM TDED_VISITS v \n" +
"WHERE v.v_collected_data.assigneeId = ?")
List<Visit> findAllByAssigneeId(String assigneeId);
The above code is used in the repository, the purpose of the query is to return all "visits" that have a matching value with the value provided. This value is a single value from inside a JSON object in a CLOB in an oracle database such as below.
{"visitId" : 1, "assigneeId" : "agr512"}
The model is made with the associated field as below.
#Column(name = "V_COLLECTED_DATA")
#Lob
private String visitJsonString;
The errors in the logs are as below
Column "V.V_COLLECTED_DATA.ASSIGNEEID" not found; SQL statement:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [SELECT *
FROM TDED_VISITS v
WHERE v.v_collected_data.assigneeId = ?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
Have also tried the below SQL query but given the error that the function JSON_VALUE was not found.
#Query(nativeQuery = true, value = "SELECT *\n" +
"FROM TDED_VISITS v \n" +
"WHERE JSON_VALUE(V_COLLECTED_DATA, '$.assigneeId') = ?")
Caused by: org.springframework.orm.jpa.JpaSystemException: could not prepare statement; nested exception is org.hibernate.exception.GenericJDBCException: could not prepare statement
Have spent a few days looking for similar problems for other people, but to no avail. Appreciate if anyone can help, thanks!

H2 does not support accessing JSON attributes. See here for a list of supported functions: https://www.h2database.com/html/functions.html

Related

H2 show value of DB_CLOSE DELAY (set by SET DB_CLOSE_DELAY)

The H2 Database has a list of commands starting with SET, in particular SET DB_CLOSE_DELAY. I would like to find out what the value of DB_CLOSE_DELAY is. I am using JDBC. Setting is easy
cx.createStatement.execute("SET DB_CLOSE_DELAY 0")
but none of the following returns the actual value of DB_CLOSE_DELAY:
cx.createStatement.executeQuery("DB_CLOSE_DELAY")
cx.createStatement.executeQuery("VALUES(#DB_CLOSE_DELAY)")
cx.createStatement.executeQuery("GET DB_CLOSE_DELAY")
cx.createStatement.executeQuery("SHOW DB_CLOSE_DELAY")
Help would be greatly appreciated.
You can access this and other settings in the INFORMATION_SCHEMA.SETTINGS table - for example:
String url = "jdbc:h2:mem:;DB_CLOSE_DELAY=3";
Connection conn = DriverManager.getConnection(url, "sa", "the password goes here");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SETTINGS where name = 'DB_CLOSE_DELAY'");
while (rs.next()) {
System.out.println(rs.getString("name"));
System.out.println(rs.getString("value"));
}
In this test, I use an unnamed in-memory database, and I explicitly set the delay to 3 seconds when I create the DB.
The output from the print statements is:
DB_CLOSE_DELAY
3

Linq to entities giving error when generic repository is used with List<T> object

In my ASP.NET Web API project, I am trying to use the generic repositories with the List objects under one of the methods. But it is throwing exception
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
System.Data.Entity.Core.EntityCommandExecutionException: Calling 'Read' when the data reader is closed is not a valid operation. --->
System.Data.SqlClient.SqlException: Execution Timeout Expired. The
timeout period elapsed prior to completion of the operation or the
server is not responding. ---> System.ComponentModel.Win32Exception:
The wait operation timed out
lstFinalResult object contains few rows. partnerRepo is a generic repo and will have data at the later stage, i suppose.
Please advise, where am i making the mistake. Can we mix the List with generic repository objects in the linq query ?
Here is the linq code :-
List<UserDocumentResult> lstFinalResult = new List<UserDocumentResult>();
foreach (DocumentMapping dm in lstMappings)
{
lstFinalResult.Add(new UserDocumentResult { PID = dm.PartnerID,
DocMappingID = dm.DocumentMappingID,
EntityType = "",
Name = ""
});
}
var partnerRepo = _docRepository.PtGenericRepo.Get();
var entityCodesRepo = _docRepository.EntityCodeGenericRepo.Get();
---While debugging, I am getting error in the below code only.
var qualifiedPartnerSet = (from tmp in lstFinalResult
join px in partnerRepo on tmp.PID equals px.PartnerID
join ecx in entityCodesRepo on px.EntityCodeID equals ecx.EntityCodeID
select new UserDocumentResult
{
PID = px.PartnerID,
MappingID = tmp.MappingID,
EntityType = ecx.DisLabel.Trim(),
Name = px.NameLine1.Trim() + px.NameLine2.Trim(),
}).ToList();

QueryRunner returning "ORA-00972: identifier is too long" passing the value as a parameter

I can't figure out why using a bind variable in the following code fails, but hard coding it works.
It also works if I just put a rownum < 2 clause instead of the id clause.
None: Using bind variables works just fine in other parts of the code.
Database Info:
Oracle 12c
The ID column is a VARCHAR2(34).
Works:
org.apache.commons.dbutils.QueryRunner remote = ...;
String searchId = "13056899429626141414864120X"
String sql = toString("SELECT * FROM ", remoteOwner, ".table_name WHERE id = '"+searchId+"'");
result = remote.query(sql, new MapListHandler());
Fails:
org.apache.commons.dbutils.QueryRunner remote = ...;
String searchId = "13056899429626141414864120X"
String sql = toString("SELECT * FROM ", remoteOwner, ".table_name WHERE id = ?");
result = remote.query(sql, new MapListHandler(), searchId);
Exception:
Exception in thread "main" java.sql.SQLException: ORA-00972: identifier is too long
Query: SELECT * FROM SCHEMA_NAME.table_name WHERE id = ? Parameters: [13056899429626141414864120X]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:527)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:391)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:329)
Root Exception (swallowed):
java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1018)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Odscrarr.doODNY(T4C8Odscrarr.java:96)
at oracle.jdbc.driver.T4CPreparedStatement.doDescribe(T4CPreparedStatement.java:717)
at oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:4404)
at oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:52)
at oracle.jdbc.driver.OracleStatement.getResultSetMetaData(OracleStatement.java:4387)
at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(OraclePreparedStatement.java:5581)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getMetaData(OraclePreparedStatementWrapper.java:1509)
at oracle.jdbc.driver.OracleParameterMetaData.getParameterMetaData(OracleParameterMetaData.java:70)
at oracle.jdbc.driver.OraclePreparedStatement.getParameterMetaData(OraclePreparedStatement.java:12861)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getParameterMetaData(OraclePreparedStatementWrapper.java:1551)
at org.apache.commons.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221)
at org.apache.commons.dbcp.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:221)
at org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:341)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:386)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:329)
Imported Jars:
.m2\repository\junit\junit\4.12\junit-4.12.jar
.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar
.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar
.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar
.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
.m2\repository\org\apache\logging\log4j\log4j-api\2.8\log4j-api-2.8.jar
.m2\repository\org\apache\logging\log4j\log4j-core\2.8\log4j-core-2.8.jar
.m2\repository\org\apache\logging\log4j\log4j-jcl\2.8\log4j-jcl-2.8.jar
.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar
.m2\repository\commons-dbcp\commons-dbcp\1.4\commons-dbcp-1.4.jar
.m2\repository\commons-pool\commons-pool\1.5.4\commons-pool-1.5.4.jar
.m2\repository\com\oracle\ojdbc6\12.1.0.2.0\ojdbc6-12.1.0.2.0.jar
.m2\repository\com\oracle\oraclepki\12.1.0.2.0\oraclepki-12.1.0.2.0.jar
.m2\repository\com\oracle\osdt_cert\12.1.0.2.0\osdt_cert-12.1.0.2.0.jar
.m2\repository\com\oracle\osdt_core\12.1.0.2.0\osdt_core-12.1.0.2.0.jar
.m2\repository\commons-dbutils\commons-dbutils\1.7\commons-dbutils-1.7.jar

org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query

I used oracle in my application.
I have problem using this code :
import org.hibernate.Hibernate;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Query;
....
....
.....
public void insertGR(String id,String num) {
String query = "execute md_pkg.insert_Gr("+id+"," + num + ")";
SQLQuery sqlQuery = this.getSession().createSQLQuery(query);
sqlQuery.executeUpdate();
}
in jboss consol I have this error :
SQL Error: 900, SQLState: 42000
ORA-00900: invalid SQL statement
org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at
but when I used sqldevelopper I do not have any problems
execute execute md_pkg.insert_Gr(9,25)
ORA-900: Invalid SQL statement should give you enough clues as to what's going on/wrong. Your statement to be executed is not SQL, it is an attempt to call a PL/SQL stored procedure. So, instead of
"execute md_pkg.insert_Gr("+id+"," + num + ")"
you should (maybe! I don't know Hibernate at all) rather
"call md_pkg.insert_Gr("+id+"," + num + ")"
or
"begin md_pkg.insert_Gr("+id+"," + num + "); end;"
and instead of using the SQLQuery class try and find something capable of executing stored procedures or anonymous PL/SQL blocks.
PS: I don't know Hibernate at all, so I can't help you finding the correct class.

Getting syntax error at the end of the input while executing a query using postgres java driver

Have the following query that is giving error while executing through java driver, no errors while executing on DBVisualizer
SELECT pr.id,
pr.name,
CDPC.category_id,
CDPC.category_depth,
CDPC.product_count,
pr.primary_category_id
FROM ics_products_to_include_tmp inc
INNER JOIN catalog.products pr ON inc.product_id = pr.id
INNER JOIN catalog.products_in_categories pic ON pic.product_id = pr.id AND pic.active = true
INNER JOIN catalog.categories CC ON CC.id = pic.category_id AND CC.active = true
INNER JOIN category_depth_product_count_tmp CDPC
ON CDPC.category_id = CC.id
AND NOT EXISTS (SELECT *
FROM ics_products_cds_ids_tmp cds
WHERE cds.product_id = pr.id)
WHERE pr.site_id = '150'
ORDER BY pr.id
Here is the error
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at end of input
Position: 495
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381)
at com.cnetchannel.ics.loader.IntermediateDatafeedGenerator.main(RRToIntermediateLoader.java:798)
Disconnected from the target VM, address: '127.0.0.1:51077', transport: 'socket'
Try using the Dollar-quoted notation.
Instead of having pr.site_id = '150' try it with something like
pr.site_id = $$150$$
Most probably your JDBC driver has problem distinguishing the two different quotes ' (&#39) and ` (&#96)

Resources