I'm using a custom #Query with Spring JPA like this:
#Query(value = "select ua from USER_ACCOUNT ua where SUBSTRING(ssn, -4, 4) = :ssn and last_nm = :lastName and birth_dt = :dateOfBirth")
UserAccount findByLastFourOfSSNAndLastNameAndDateOfBirth(#Param("ssn") String lastFourOfSSN, #Param("lastName") String lastName, #Param("dateOfBirth") Date dateOfBirth);
It works without any problems when I run it locally, but as soon as I deploy it out to the development environment I get:
[2017-12-19T23:02:59,048] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper SQL Error: 904, SQLState: 42000
[2017-12-19T23:02:59,048] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper ORA-00904: "SUBSTRING": invalid identifier
[2017-12-19T23:02:59,049] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[User Store] Servlet.service() for servlet [User Store] in context with path [] threw exception [org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
java.sql.SQLSyntaxErrorException: ORA-00904: "SUBSTRING": invalid identifier
The development environment is pretty much identical to my local. Same database, same version of Tomcat. Am I just missing something obvious here?
EDIT: SQL being generated:
select useraccoun0_.GUID as GUID1_5_, useraccoun0_.CREATED_BY as CREATED_BY2_5_, useraccoun0_.CREATED_DT as CREATED_DT3_5_, useraccoun0_.DB_NOTE as DB_NOTE4_5_, useraccoun0_.LAST_CHANGED_BY as LAST_CHANGED_BY5_5_, useraccoun0_.LAST_CHANGED_DT as LAST_CHANGED_DT6_5_, useraccoun0_.ACCOUNT_RECOVERY_EMAIL as ACCOUNT_RECOVERY_E7_5_, useraccoun0_.ACCOUNT_RECOVERY_PHONE as ACCOUNT_RECOVERY_P8_5_, useraccoun0_.BIRTH_DT as BIRTH_DT9_5_, useraccoun0_.DISABLED_IND as DISABLED_IND10_5_, useraccoun0_.DISABLED_DT as DISABLED_DT11_5_, useraccoun0_.DISABLED_REASON as DISABLED_REASON12_5_, useraccoun0_.email as email13_5_, useraccoun0_.FAILED_LOGIN_CNT as FAILED_LOGIN_CNT14_5_, useraccoun0_.FAILED_PASSWORD_RESET_DT as FAILED_PASSWORD_R15_5_, useraccoun0_.FIRST_NM as FIRST_NM16_5_, useraccoun0_.LAST_FAILED_LOGIN_DT as LAST_FAILED_LOGIN17_5_, useraccoun0_.LAST_LOGIN_DT as LAST_LOGIN_DT18_5_, useraccoun0_.LAST_NM as LAST_NM19_5_, useraccoun0_.LOCKED_IND as LOCKED_IND20_5_, useraccoun0_.LOCKED_CNT as LOCKED_CNT21_5_, useraccoun0_.LOCKED_DT as LOCKED_DT22_5_, useraccoun0_.USER_PASSWORD as USER_PASSWORD23_5_, useraccoun0_.PASSWORD_CHANGED_DT as PASSWORD_CHANGED_24_5_, useraccoun0_.PHONE_NBR as PHONE_NBR25_5_, useraccoun0_.REQUIRE_PASSWORD_RESET_IND as REQUIRE_PASSWORD_26_5_, useraccoun0_.SSN as SSN27_5_, useraccoun0_.USER_NM as USER_NM28_5_ from USER_ACCOUNT useraccoun0_ where substr(useraccoun0_.SSN, -4, 4)=? and last_nm=? and birth_dt=?
Related
I am using spring-data-rest & hibernate to expose a table "File(Id, Name)" from a SAP IQ(Sybase IQ) database. The below error occurs when I do a "GET" on the "File" table using "curl http://localhost:8080/files/1".
2022-07-20 20:01:03 WARN [http-nio-8081-exec-1] o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: JZ0SA
2022-07-20 20:01:03 ERROR [http-nio-8081-exec-1] o.h.e.jdbc.spi.SqlExceptionHelper - JZ0SA: Prepared Statement: Input parameter not set, index: 0.
2022-07-20 20:01:03 INFO [http-nio-8081-exec-1] o.h.e.i.DefaultLoadEventListener - HHH000327: Error performing load command
org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
I have the same table in "Sybase 16" but it is working perfectly with the same code base.
Anyone faced similar issue?
Thanks in advance
I am getting an exception with spring boot with postgres DB when using a sequence generator.
Below is the stacktrace
2020-01-17 15:54:10 - SQL Error: 0, SQLState: 42P01
2020-01-17 15:54:10 - ERROR: relation "predefmapping_seq" does not exist
Position: 17
2020-01-17 15:54:13 - Error adding tags to the DB:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not
extract ResultSet
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149) ~
[hibernate-core-5.2.17.Final.jar!/:5.2.17.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157) ~
[hibernate-core-5.2.17.Final.jar!/:5.2.17.Final]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164) ~
[hibernate-core-5.2.17.Final.jar!/:5.2.17.Final]
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:790) ~[hibernate-core-
5.2.17.Final.jar!/:5.2.17.Final]
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:768) ~[hibernate-core-
5.2.17.Final.jar!/:5.2.17.Final]
at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~ [na:1.8.0_232]
Below is the Entinty class column for which the sequence is added.
#Id
#SequenceGenerator(name="PREDEFMAPPING_SEQ", sequenceName="PREDEFMAPPING_SEQ",initialValue = 1, allocationSize=1)
#GeneratedValue(strategy = GenerationType.AUTO ,generator="PREDEFMAPPING_SEQ")
#Column(name = "ID")
private long id;
Note that this has been tested with db2, oracle and mssql. However for postgres it is giving me the above exception.
The sequence name in postgres db table is "predefmap_seq" and not "PREDEFMAPPING_SEQ" as in the entity.
Most solutions suggest that I change the Generation strategy to IDENTITY however I wanted a solution which would be applicable to all (db2, oracle, mssql and postgres)
I have seted -DIGNITE_H2_DEBUG_CONSOLE in JVM parameters.
Then local H2 console started.
but exception occurred:
General error: "java.lang.UnsupportedOperationException"; SQL statement:
SELECT UPPER(VALUE) FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=? [50000-191] HY000/50000
org.h2.jdbc.JdbcSQLException: General error: "java.lang.UnsupportedOperationException"; SQL statement:
SELECT UPPER(VALUE) FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=? [50000-191]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:295)
at org.h2.command.Command.executeQuery(Command.java:213)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:110)
at org.h2.bnf.context.DbContents.readContents(DbContents.java:136)
...
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsupportedOperationException
at org.apache.ignite.internal.processors.query.h2.opt.GridH2Row.setKey(GridH2Row.java:101)
at org.h2.table.MetaTable.add(MetaTable.java:1982)
at org.h2.table.MetaTable.generateRows(MetaTable.java:940)
at org.h2.index.MetaIndex.find(MetaIndex.java:50)
at org.h2.index.BaseIndex.find(BaseIndex.java:132)
at org.h2.index.IndexCursor.find(IndexCursor.java:169)
at org.h2.table.TableFilter.next(TableFilter.java:460)
at org.h2.command.dml.Select.queryFlat(Select.java:541)
...
at org.h2.command.CommandContainer.query(CommandContainer.java:110)
at org.h2.command.Command.executeQuery(Command.java:201)
... 8 more
This is a known issue: https://issues.apache.org/jira/browse/IGNITE-3685
It is fixed in upcoming Apache Ignite 1.8.
Mapper.xml
<insert id = "insertVacation" parameterType = "Vacation">
INSERT INTO ferias (audit_dt, audit_usuario, audit_st_ope,
feri_cfun_cd_mat, feri_fepa_ano, feri_sq, feri_dt_inicio, feri_dt_fim,
feri_fsfr_cd, feri_st_pag, feri_ds_obs, feri_st_ad13sal, feri_dt_pagref,
feri_st_autorizado, fepa_st_recebe_adferias, feri_fl_periodo_ativo,
feri_dt_programacao, feri_dt_autorizacao, feri_tp_programacao,
feri_fl_adiantamento_durante, feri_fl_13_durante )
VALUES (#{auditDate, typeHandler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"}, #{auditUser}, #{auditStatus}, #{userCode},
#{currentYear}, #{sequencial}, #{initialPeriod}, #{finalPeriod},
#{status}, #{paymentStatus}, #{note}, #{advance13th}, #{paymentDate},
#{statusAuthorized}, #{additional}, #{activePeriod}, #{scheduleDate},
#{authorizationDate}, #{typeProgramming}, #{advanceVacation},
#{advance13thVacation} )
</insert>
mybatis-config.xml
<typeHandlers>
<typeHandler javaType="org.joda.time.DateTime" jdbcType="DATE" handler="br.gov.df.terracap.grh.util.DateTimeTypeHandler"/>
<typeHandler javaType="org.joda.time.LocalDateTime" jdbcType="TIMESTAMP" handler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"/>
</typeHandlers>
Error when test the Insert
### Error updating database. Cause:
org.apache.ibatis.builder.BuilderException: Error resolving class .
Cause: org.apache.ibatis.type.TypeException: Could not resolve type
alias '"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"'.
Cause: java.lang.ClassNotFoundException: Cannot find class:
"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler" ### Cause:
org.apache.ibatis.builder.BuilderException: Error resolving class .
Cause: org.apache.ibatis.type.TypeException: Could not resolve type
alias '"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"'.
Cause: java.lang.ClassNotFoundException: Cannot find class:
"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"
org.apache.ibatis.exceptions.PersistenceException
VALUES (#{auditDate, typeHandler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"}
Correct:
VALUES (#{auditDate,
typeHandler=br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler}
*without quotes
I am intermittently getting the following jdbc error with my oracle db (in remote linux machine)
java.sql.SQLException: ORA-03120: two-task conversion routine: integer overflow
The query that mostly breaks(not the only one!) looks like this, note that I am using Groovy Sql
String insertScript =
"""
INSERT INTO data_table (invoke_id , trans_type , trans_from ,
trans_to , serv_type ,msg_type , man_id , recip_id ,
trx_id , part_id , msg_orig_time , create_time ,
action_code , num_ranges , use_trx_id, due_date,owner,route,lsa,
cl_id,hl_id,requ_type,lnp_type,use_invoke_id)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
"""
def params = [invokeId,transType,transFrom,transTo,servType,msgType,man,recip,portId,owner,
now,now,"W",1,trxId,dueDate,owner," ", "LSA","CCH"," ","Basic","lspp",invokeId]
sql.execute insertScript, params
What I do not understand is why my queries work some time and not other times. Generally it will happen during the first run and only rarely appear in subsequent runs.
[UPDATE] I am getting this error sometimes on application startup also, when spring tries to load its context. I am using spring and dbcp for the connection pooling.
Caused by: org.apache.commons.dbcp.SQLNestedException: Error preloading the connection pool
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1238)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
... 46 more
Caused by: java.sql.SQLException: ORA-03120: two-task conversion routine: integer overflow
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:204)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:406)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:799)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:368)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.pool.impl.GenericObjectPool.addObject(GenericObjectPool.java:1059)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1235)
... 49 more