From e2a9702c464390a324ef17e81781819ca77e0848 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 1 May 2014 23:01:55 +0000 Subject: [PATCH] This getGeneratedKeys business doesn't seem to work for us on mysql. Trying a catch/fallback. This should at least provide a workaround for now... --- .../com/samskivert/depot/impl/IdentityValueGenerator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/samskivert/depot/impl/IdentityValueGenerator.java b/src/main/java/com/samskivert/depot/impl/IdentityValueGenerator.java index 76d6cce..1bab389 100644 --- a/src/main/java/com/samskivert/depot/impl/IdentityValueGenerator.java +++ b/src/main/java/com/samskivert/depot/impl/IdentityValueGenerator.java @@ -12,6 +12,8 @@ import java.sql.Statement; import com.samskivert.jdbc.DatabaseLiaison; import com.samskivert.depot.annotation.GeneratedValue; +import static com.samskivert.depot.Log.log; + /** * Generates primary keys using an identity column. */ @@ -44,7 +46,11 @@ public class IdentityValueGenerator extends ValueGenerator if (stmt != null && conn.getMetaData().supportsGetGeneratedKeys()) { ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { - return rs.getInt(column); + try { + return rs.getInt(column); + } catch (SQLException e) { + log.info("Unable to get generated key, falling back", "errmsg", e.getMessage()); + } } } return liaison.lastInsertedId(conn, _dm.getTableName(), column);