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:db...@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:ric...@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-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org

Reply via email to