Yes, that would work.  You could even do the following:

Person aPerson = new Person();
aPerson.setFirstname("Joe");
aPerson.setLastname("Bloggs")
Integer id = (Integer) sqlMap.insert("insert", aPerson);

// id.intValue() would be the same as aPerson.getPersonId().

This way, you don't have to set anything via the keyProperty attribute of <selectKey>.

Zarar




----- Original Message ----- From: "Alan Chandler" <[EMAIL PROTECTED]>
To: <user-java@ibatis.apache.org>
Sent: Friday, September 30, 2005 4:15 PM
Subject: Re: Trying to understand selectKey


On Friday 30 Sep 2005 19:57, Larry Meadors wrote:
You would do this (or close):

<insert id="insert">
INSERT INTO person (lastname, firstname) values (#lastname#, #firstname#) <selectKey property="personId">SELECT curval('persons_id_seq')</selectKey>
</insert>

After calling the insert method, your bean (or map) would have the
personId property set.

Just to be clear, if I now do

Person aPerson = new Person();
aPerson.setFirstname("Joe");
aPerson.setLastname("Bloggs")
sqlMap.insert("insert", aPerson);

int anID=aPerson.getPersonId()

anID would end up with the id of the inserted record?


--
Alan Chandler
http://www.chandlerfamily.org.uk



Reply via email to