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 Zach Visagie <za...@ipay.co.za> on 2008/06/05 13:08:57 UTC

jdbc3 generated keys for the desperate

I have created a patch for basic jdbc3 support to ibatis 2.3.2. It is
not intended for inclusion, since it was done on a least intrusion basis
and is frankly a real hack.

To not modify any configs I use selectKey in the following manner:

   <selectKey keyProperty="id" resultClass="java.lang.Long">
      KEY_COLUMN: mytable_id
   </selectKey>

The KEY_COLUMN: prefix serves as a marker to know that getGeneratedKeys
is required. The single appropriate column name is passed in and is used
to call prepareStatement( String sql, String[] columns ) with a single
element in the String[]. It will not work with drivers that don't
support this.

The patch has been added to the JIRA issue concerning this matter:
http://issues.apache.org/jira/browse/IBATIS-142

Note for postgres:
For postgres which does not support getGeneratedKeys consider wrapping
their PreparedStatement with your own which analyses the sql for the
table name for insert queries and then uses the following to retrieve
the key's value:

select currval(pg_get_serial_sequence('table_name','column_name'))


ola
z