ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Jenkins <krisajenk...@yahoo.co.uk>
Subject Re: OnJava article
Date Thu, 03 Feb 2005 15:36:58 GMT
Worth noting that the parameter bean will not be affected.  So (if this 
is what you want to accomplish) you need to do:

public void saveContact( Contact contact ) throws SQLException {
    Integer id = sqlMap.insert("insertContact",contact);

    contact.setId( id );

    log.debug( "I have now saved your object and given it the correct 
id." );
}

Kris

Richard Yee wrote:

> Mike,
> According to the JavaDocs for the insert method:
>
> Executes a mapped SQL INSERT statement. Insert is a bit different from 
> other update methods, as it provides facilities for returning the 
> primary key of the newly inserted row (rather than the effected rows). 
> This functionality is of course optional.
>
> The parameter object is generally used to supply the input data for 
> the INSERT values.
>
> *Parameters:*
>
>     id - The name of the statement to execute. 
>     parameterObject - The parameter object (e.g. JavaBean, Map, XML
>     etc.). 
>
> *Returns:*
>
>     The primary key of the newly inserted row. This might be
>     automatically generated by the RDBMS, or selected from a sequence
>     table or other source. 
>
> -Richard
>
>
> At 05:21 AM 2/3/2005, you wrote:
>
>> Overall, I think it's a really good article. But one question about 
>> this example...
>> public void contactInsert() throws SQLException, IOException { 
>> sqlMap.startTransaction(); try { sqlMap.startTransaction(); Contact 
>> contact = new Contact(); contact.setContactId(3); 
>> contact.setFirstName("John"); contact.setLastName("Doe"); 
>> sqlMap.insert("insertContact",contact); sqlMap.commitTransaction(); } 
>> finally{ sqlMap.endTransaction(); } }
>> Inside of our Java code, we create a Contact object, populate its 
>> values, and then call sqlMap.insert(), passing the name of the query 
>> that we want to execute and the Contact. *This method will insert the 
>> new contact and return the primary key of the newly inserted 
>> contact.* Is that last sentence true? I am using <selectKey> now.
>> Mike
>>
>>
>>
>> Do you Yahoo!?
>> Yahoo! Search presents - Jib Jab's 'Second Term' 
>> <http://us.rd.yahoo.com/evt=30648/*http://movies.yahoo.com/movies/feature/jibjabinaugural.html>

>
>


-- 
Kris Jenkins
Email:  kris@jenkster.com
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/



Mime
View raw message