diff --git a/core/src/main/java/org/hibernate/id/IdentityGenerator.java b/core/src/main/java/org/hibernate/id/IdentityGenerator.java index 37da1d7891..62be3ea96b 100644 --- a/core/src/main/java/org/hibernate/id/IdentityGenerator.java +++ b/core/src/main/java/org/hibernate/id/IdentityGenerator.java @@ -70,10 +70,19 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { public Serializable executeAndExtract(PreparedStatement insert) throws SQLException { insert.executeUpdate(); - return IdentifierGeneratorFactory.getGeneratedIdentity( - insert.getGeneratedKeys(), - persister.getIdentifierType() - ); + ResultSet rs = null; + try { + rs = insert.getGeneratedKeys(); + return IdentifierGeneratorFactory.getGeneratedIdentity( + rs, + persister.getIdentifierType() + ); + } + finally { + if ( rs != null ) { + rs.close(); + } + } } }