ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Douglas Bell" <DB...@boingo.com>
Subject RE: [iBatis 3] insert/update via annotation w/ object example
Date Wed, 26 Aug 2009 22:55:41 GMT
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 <DBell@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


Mime
View raw message