I'm trying to insert a list to Mybatis and getting the foloowing error:
org.apache.ibatis.binding.BindingException: Parameter '__frch_e_0' not found. Available parameters are [list]
Can you please let know what I'm missing. Thanks
DAO interface:
void saveErrorMessageList(List<ErrorMessage> emList);
XML:
<insert id="saveErrorMessageList" parameterType="java.util.List">
{call
declare
ID PLS_INTEGER;
begin
<foreach collection="list" item="e" index="index" >
SELECT SEQ_ERR_ID.NEXTVAL into ID FROM DUAL;
INSERT INTO ERR (ERR_ID, CREAT_TS,
MSG_CD, MSG_TXT) values (ID,CURRENT_TIMESTAMP,
#{e.code}, #{e.message});
</foreach>
end
}
</insert>
Error Message:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_e_0' not found. Available parameters are [list]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
at com.sun.proxy.$Proxy11.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy12.saveBeneErrorMessageList(Unknown Source)
at ...
... 35 more
check column name and bean field name in sql
try to update mybatis version. when i use 3.3.0 have this error, but use 3.4.1 it is ok
Please check foreach tag for collection attribute. I feel value should be "emList" or add #Param (org.apache.ibatis.annotations.Param) in interface method.
<foreach collection="emList" item="e" index="index" >
INSERT INTO ERR (ERR_ID, CREAT_TS,
MSG_CD, MSG_TXT) values (CURRENT_TIMESTAMP,
#{e.code}, #{e.message});
</foreach>
</insert>
Related
I'm using mybatis in spring and spring version is 4.
When using Oracle insert all as:
<insert id = "testMultipleInserts" parameterType="java.util.List">
<foreach collection="list" item="element" index="index" open="insert all" close="select * from dual" separator=" " >
Into Test_A (Description) values (#{element.description})
</foreach>
</insert>
If you run this way, you'll get an error.
<update id = "testMultipleInserts" parameterType="java.util.List">
<foreach collection="list" item="element" index="index" open="insert all" close="select * from dual" separator=" " >
Into Test_A (Description) values (#{element.description})
</foreach>
</update>
It's going all too well when you run like this. I wonder if there is an update difference between insert in tag. I know insert and update tags have no difference in mybatis. Is there any specific way to set up springs or mybatis?
I'm using Oracle's XMLQuery database function to read a SOAP Webservice response, however the response element "result" includes namespace clause (xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/") next to the element name, so the XMLQuery fails to read the element's value.
This is the Webservice response body I received, and I'm trying to read the "result"
<env:Body>
<ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">
<result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>
</ns0:getFlowTaskInstanceStatusResponse>
</env:Body>
.
The following Select statement returns NULL
SELECT xmlcast(XMLQuery('//result' PASSING l_xmldata RETURNING CONTENT) as varchar2(900))
into l_extract
from dual;
The XMLQuery function will return "COMPLETED" in case I remove the namespace text from the XML response !!! However this is not a practical workaround.
BR
Hany
You have two options (I added an "env" namespace to make the xml valid):
include the namespaces in the query:
WITH test AS
(SELECT xmltype('
<env:Body xmlns:env="myenv">
<ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">
<result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>
</ns0:getFlowTaskInstanceStatusResponse>
</env:Body>') AS data
FROM dual
)
SELECT CAST( extractValue(test.data, '//ns0:result','xmlns:env="myenv" xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/') AS VARCHAR2(900) )
FROM test
ignore the namespaces
WITH test AS
(SELECT xmltype('
<env:Body xmlns:env="myenv">
<ns0:getFlowTaskInstanceStatusResponse xmlns:ns0="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">
<result xmlns="http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/">COMPLETED</result>
</ns0:getFlowTaskInstanceStatusResponse>
</env:Body>') AS data
FROM dual
)
SELECT CAST( extractValue(test.data, '//*[local-name() = "result"]') AS VARCHAR2(900) )
FROM test
I'm struggling in creating a dynamic query with null check on date in spel using spring data. My query is:
#Query(nativeQuery = true, value = "select a.* from TABLE a where"
+ "(:#{#DateFrom} is null or a.F_DATE >= trunc(:#{#DateFrom}))")
List<Acc> getAccList(#Param("DateFrom") #Temporal(TemporalType.DATE) Date datefrom);
When I run this query with valid date it works, but when I pass null date I get following error:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Stack trace:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at com.ing.cbp.commons.util.logging.sql.LogablePreparedStatement.executeQuery(LogablePreparedStatement.java:77)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
... 78 common frames omitted
It seems oracle considers the NULL value a binary and than fails when it tries to perform trunc on it. Casting it to a Date should help. So the resulting query should look like this:
select a.* from TABLE a where (:#{#DateFrom} is null
or a.F_DATE >= trunc(CAST(:#{#DateFrom} AS DATE))
You need add one whitespace after 'where' keyword.
#Query(nativeQuery = true, value = "select a.* from TABLE a where "
+ "(:#{#DateFrom} is null or a.F_DATE >= trunc(:#{#DateFrom}))")
List<Acc> getAccList(#Param("DateFrom") #Temporal(TemporalType.DATE) Date datefrom);
This is ThreadGroup:
This is JDBC Connection Config:
![this is JDBC CONNECTIIN CONFIG][2]
The SQL:
SELECT siteid FROM tky_tab_bbsdata WHERE name = ?
And then it throws exception:
java.sql.SQLException: ORA-01008: 并非所有变量都已绑定
the request is :SELECT siteid FROM tky_tab_bbsdata where name = ?
梁段
VARCHAR
I don't know how to solve this problem, the SQL may be right!
You don't need to use parameter outside SQL statement:
Remove values from: parameter values and parameter type
In SQL statement replace your = ? with a real value, use = '[value]'
I am trying to execute sql native query using hibernate 3.3.2.GA.
I have following query.
session.createSQLQuery("SELECT {dept1.*}, {dept2.*} FROM Dept d1, Dept d2 WHERE d1.deptId = d2.deptId").
addEntity("dept1",com.test.pojo.Dept.class).
addEntity("dept2",com.test.pojo.Dept.class).
list();
Mapping file for Dept class is
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.pojo.Dept">
<id column="deptId" name="deptId" type="long">
<generator class="native"/>
</id>
<version name="version" access="field" column="version"></version>
<property name="deptName" type="string" column="deptName"/>
<set name="emps" cascade="all" inverse="true">
<key column="deptId"></key>
<one-to-many class="com.test.pojo.Emp"/>
</set>
</class>
</hibernate-mapping>
But why I get following error? It is converting my query to
SELECT dept1.**deptId as deptId1_0_, **dept1.**version as
version1_0_, **dept1.**deptName as deptName1_0_, **dept2.**deptId as
deptId1_1_, **dept2.**version as version1_1_, **dept2.**deptName as
deptName1_1_ **FROM Dept d1, Dept d2 WHERE d1.deptId = d2.deptId.
Hibernate: SELECT dept1.deptId as deptId1_0_, dept1.version as
version1_0_, dept1.deptName as deptName1_0_, dept2.deptId as
deptId1_1_, dept2.version as version1_1_, dept2.deptName as
deptName1_1_ FROM Dept d1, Dept d2 WHERE d1.deptId = d2.deptId
20:43:41,109 WARN JDBCExceptionReporter:100 - SQL Error: 904,
SQLState: 42000 20:43:41,109 ERROR JDBCExceptionReporter:101 -
ORA-00904: "DEPT2"."DEPTNAME": invalid identifier
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1723)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
at com.test.test.Test1.main(Test1.java:96)
Caused by: java.sql.SQLException: ORA-00904: "DEPT2"."DEPTNAME": invalid identifier
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:590)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1973)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2599)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2963)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:658)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:584)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 7 more
It should be
session.createSQLQuery(
"SELECT {dept1.*}, {dept2.*} FROM Dept dept1, Dept dept2 WHERE dept1.deptId = dept2.deptId")
.addEntity("dept1",com.test.pojo.Dept.class)
.addEntity("dept2",com.test.pojo.Dept.class)
.list();
If you was misled by the documentation (18.1.4. Returning multiple entities), there is a bug there (HHH-2976), feel free to vote for it.
Try Google with the ORA-XXX codes. From http://www.dba-oracle.com/t_ora_00904_string_invalid_identifier.htm
Question: I am running a SQL
statement and I get a SQL*Plus error
ORA-00904 invalid identifier.
Answer: When ORA-00904 occurs, you
must enter a valid column name as it
is either missing or the one entered
is invalid. The "invalid identifier"
most common happens when you are
referencing an invalid alias in a
select statement. The Oracle docs
note this on the ORA-00904 error: