ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zach Visagie <za...@ipay.co.za>
Subject jdbc3 generated keys for the desperate
Date Thu, 05 Jun 2008 11:08:57 GMT

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

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:

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'))


View raw message