Auto Generated Keys
Last Update: Aug. 5th 2006.
If the database used with Mr. Persister supports it,
it is possible to access keys generated by the database
as results of insert SQL statements. The auto generated keys are accessed
via the IGenericDao interface, via the getUpdateResults() method. The method
looks like this:
public List getUpdateResults();
The getUpdateResults() method returns a list of UpdateResult instances. Each UpdateResult instance
corresponds to one SQL update executed via the IGenericDao. Each UpdateResult instance contains
the number of records affected by the corresponding update, and a List of keys generated by that
NOTE: Mr. Persister currently only reads the keys generated after inserts. That means, that only
UpdateResult instances that match an insert will contain generated keys. All other UpdateResult
instances will contain an empty list.
Of the databases supported by Mr. Persister, only Derby, H2, and MySQL supports returning
the generated keys (via the JDBC driver - the Statement interface). HSQLDB requires you
to call a special function ( "CALL IDENTITY()" ) to obtain the latest generated key by that
connection. Mr. Persister could do this automatically in the background, but currently doesn't.
In the future Mr. Persister may insert the auto generated keys directly into the inserted
objects, but currently doesn't.
Back to Top