You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Douglas Bell <DB...@boingo.com> on 2009/08/26 19:10:00 UTC
[iBatis 3] insert/update via annotation w/ object example
I've been through the user guide and the test cases but don't see a good
example of doing an insert or update with a Object using a annotation
e.g.
@Update("INSERT INTO foo (bar_1, bar_2) VALUES (#{bar1}, #{bar2})")
void update(SomeObject obj);
What am I missing?
-Doug
From: Anta [mailto:antany84@gmail.com]
Sent: Wednesday, August 26, 2009 2:35 AM
To: user-java@ibatis.apache.org
Subject: Calling oracle procedure from Java using iBatis
Hi All,
I have a stored procedure as like below in oracle db
create or replace PROCEDURE employee_to_delete (i_condition VARCHAR2)
IS
TYPE r_cursor IS REF CURSOR;
actiontype VARCHAR2 (20) := 'DELETING';
del_cur_temp r_cursor;
cursor_table employee%ROWTYPE;
sql_stmt VARCHAR2 (10000);
BEGIN
sql_stmt := 'select * from employee ' || i_condition;
OPEN del_cur_temp FOR sql_stmt;
LOOP
FETCH del_cur_temp
INTO cursor_table;
DELETE FROM employee
WHERE name = cursor_table.name
AND no = cursor_table.no
AND dept = cursor_table.dept;
EXIT WHEN del_cur_temp%NOTFOUND;
END LOOP;
commit;
END;
I have add the following line in my sql map file
And I tried to execute the same using the following java code
String str= "pavan";
sqlMap.queryForObject("deleteUser",str);
The records are deleted successfully. After that I am getting the
exception like below.
Exception in thread "main"
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in SqlMap.xml.
--- The error occurred while applying a parameter map.
--- Check the deleteUser-InlineParameterMap.
--- Check the output parameters.
--- Cause: java.lang.ArrayIndexOutOfBoundsException: 0
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryW
ithCallback(MappedStatement.java:204)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryF
orObject(MappedStatement.java:120)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlM
apExecutorDelegate.java:518)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlM
apExecutorDelegate.java:493)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSes
sionImpl.java:106)
at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClie
ntImpl.java:82)
at Main.main(Main.java:16)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at
com.ibatis.sqlmap.engine.exchange.PrimitiveDataExchange.setData(Primitiv
eDataExchange.java:51)
at
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.refreshParameter
ObjectValues(ParameterMap.java:141)
at
com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.postProces
sParameterObject(ProcedureStatement.java:26)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryW
ithCallback(MappedStatement.java:193)
... 6 more
Please any one explain me why this exception occurs also how to solve
it.
Thanks in Advance
Ant
________________________________
View this message in context: Calling oracle procedure from Java using
iBatis
<http://www.nabble.com/Calling-oracle-procedure-from-Java-using-iBatis-t
p25149496p25149496.html>
Sent from the iBATIS - User - Java mailing list archive
<http://www.nabble.com/iBATIS---User---Java-f370.html> at Nabble.com.
Re: [iBatis 3] insert/update via annotation w/ object example
Posted by Clinton Begin <cl...@gmail.com>.
Can you submit a JIRA ticket with the NPE? iBATIS should never throw an
NPE...
Clinton
On Wed, Aug 26, 2009 at 4:55 PM, Douglas Bell <DB...@boingo.com> wrote:
> Answered my own question... In case anyone is wondering.
>
> I had to set both useGeneratedKeys to true and the keyProperty value.
>
> @Insert("INSERT INTO test (test_value) VALUES (#{value})")
> @Options(useGeneratedKeys = true, keyProperty = "id")
> void insert(TestObj testObj);
>
> -----Original Message-----
> From: Douglas Bell [mailto:DBell@boingo.com]
> Sent: Wednesday, August 26, 2009 12:33 PM
> To: user-java@ibatis.apache.org
> Subject: RE: [iBatis 3] insert/update via annotation w/ object example
>
> Thanks Rick,
>
> It was a typo on my part :| works as expected now.
>
> One last question.
>
> I have an Object with two parameters id and value. ID is a generated key
> I want that key to be populated in the object on insert. Reading through
> the docs it looks like this is the correct solution...
>
> @Insert("INSERT INTO test (test_value) VALUES (#{value})")
> @Options(keyProperty = "id")
> void insert(TestObj testObj);
>
> ... But I get a null pointer.
>
> -----Original Message-----
> From: Rick [mailto:rickcr@gmail.com]
> Sent: Wednesday, August 26, 2009 10:34 AM
> To: user-java@ibatis.apache.org
> Subject: Re: [iBatis 3] insert/update via annotation w/ object example
>
> On Wed, Aug 26, 2009 at 1:10 PM, Douglas Bell <DB...@boingo.com> wrote:
> >
> > I've been through the user guide and the test cases but don't see a
> good example of doing an insert or update with a Object using a
> annotation
>
> > @Update("INSERT INTO foo (bar_1, bar_2) VALUES (#{bar1}, #{bar2})")
> >
> > void update(SomeObject obj);
>
> > What am I missing?
>
> Did you try it? Works fine for me (I'd use @Insert though for inserts,
> but @Update works as well.)
>
> I do agree though that it probably should be shown in the docs.
> Clinton, I'll add that to the wiki.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
RE: [iBatis 3] insert/update via annotation w/ object example
Posted by Douglas Bell <DB...@boingo.com>.
Answered my own question... In case anyone is wondering.
I had to set both useGeneratedKeys to true and the keyProperty value.
@Insert("INSERT INTO test (test_value) VALUES (#{value})")
@Options(useGeneratedKeys = true, keyProperty = "id")
void insert(TestObj testObj);
-----Original Message-----
From: Douglas Bell [mailto:DBell@boingo.com]
Sent: Wednesday, August 26, 2009 12:33 PM
To: user-java@ibatis.apache.org
Subject: RE: [iBatis 3] insert/update via annotation w/ object example
Thanks Rick,
It was a typo on my part :| works as expected now.
One last question.
I have an Object with two parameters id and value. ID is a generated key
I want that key to be populated in the object on insert. Reading through
the docs it looks like this is the correct solution...
@Insert("INSERT INTO test (test_value) VALUES (#{value})")
@Options(keyProperty = "id")
void insert(TestObj testObj);
... But I get a null pointer.
-----Original Message-----
From: Rick [mailto:rickcr@gmail.com]
Sent: Wednesday, August 26, 2009 10:34 AM
To: user-java@ibatis.apache.org
Subject: Re: [iBatis 3] insert/update via annotation w/ object example
On Wed, Aug 26, 2009 at 1:10 PM, Douglas Bell <DB...@boingo.com> wrote:
>
> I've been through the user guide and the test cases but don't see a
good example of doing an insert or update with a Object using a
annotation
> @Update("INSERT INTO foo (bar_1, bar_2) VALUES (#{bar1}, #{bar2})")
>
> void update(SomeObject obj);
> What am I missing?
Did you try it? Works fine for me (I'd use @Insert though for inserts,
but @Update works as well.)
I do agree though that it probably should be shown in the docs.
Clinton, I'll add that to the wiki.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
RE: [iBatis 3] insert/update via annotation w/ object example
Posted by Douglas Bell <DB...@boingo.com>.
Thanks Rick,
It was a typo on my part :| works as expected now.
One last question.
I have an Object with two parameters id and value. ID is a generated key
I want that key to be populated in the object on insert. Reading through
the docs it looks like this is the correct solution...
@Insert("INSERT INTO test (test_value) VALUES (#{value})")
@Options(keyProperty = "id")
void insert(TestObj testObj);
... But I get a null pointer.
-----Original Message-----
From: Rick [mailto:rickcr@gmail.com]
Sent: Wednesday, August 26, 2009 10:34 AM
To: user-java@ibatis.apache.org
Subject: Re: [iBatis 3] insert/update via annotation w/ object example
On Wed, Aug 26, 2009 at 1:10 PM, Douglas Bell <DB...@boingo.com> wrote:
>
> I've been through the user guide and the test cases but don't see a
good example of doing an insert or update with a Object using a
annotation
> @Update("INSERT INTO foo (bar_1, bar_2) VALUES (#{bar1}, #{bar2})")
>
> void update(SomeObject obj);
> What am I missing?
Did you try it? Works fine for me (I'd use @Insert though for inserts,
but @Update works as well.)
I do agree though that it probably should be shown in the docs.
Clinton, I'll add that to the wiki.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
Re: [iBatis 3] insert/update via annotation w/ object example
Posted by Rick <ri...@gmail.com>.
On Wed, Aug 26, 2009 at 1:10 PM, Douglas Bell <DB...@boingo.com> wrote:
>
> I’ve been through the user guide and the test cases but don’t see a good example of doing an insert or update with a Object using a annotation
> @Update(“INSERT INTO foo (bar_1, bar_2) VALUES (#{bar1}, #{bar2})”)
>
> void update(SomeObject obj);
> What am I missing?
Did you try it? Works fine for me (I'd use @Insert though for inserts,
but @Update works as well.)
I do agree though that it probably should be shown in the docs.
Clinton, I'll add that to the wiki.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org