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 Härtel, Eric <E....@d-trust.net> on 2007/11/01 16:14:05 UTC

getting auto-generated key

Hello list,

I have "Person" class with several phone numbers (0-*) I have the numbers in a separate table with two columns, persId and number. When I insert the person I want to insert the phone numbers, too. So I wrote:

<insert id="insertPerson" parameterClass="Person">
	INSERT INTO Person ( salutation, degree, firstname, ) 
		VALUES ( #salutation:VARCHAR#, #degree:VARCHAR#, #firstname:VARCHAR# );
	<selectKey resultClass="int" >
		SELECT @@IDENTITY AS ID
	</selectKey>
	<iterate property="telefonNrs" conjunction="; ">
		INSERT INTO phoneNumbers (persId, number)
		VALUES ( id, #telefonNrs[]# )
	</iterate>
</insert>

The problem is: I need the auto-generated person key to insert the phone numbers. How can I get?

Greetings Eric