I've been working with jdbi for a project, but @GetGeneratedKeys does not seem to work, I've even created a Mapper Class. code as follows:
@GetGeneratedKeys(GeneratedKeysMapper.class)
@SqlUpdate(INSERT_CUSTOMIZING)
public abstract long insertCustomization(@Bind("logicalName")String logicalName,
@Bind("configurationId")int configurationId,@Bind("customizationCriteriaId") int customizationCriteriaId);
public class GeneratedKeysMapper implements
ResultSetMapper<GeneratedKeysMapper> {
@Override
public GeneratedKeysMapper map(int index, ResultSet r, StatementContext ctx)
throws SQLException {
System.out.println("mapper");
System.out.println("index:"+index);
System.out.println("rs:"+r.getFetchSize());
System.out.println("context:"+ctx.isReturningGeneratedKeys());
return null;
}
}
I've followed all documentation regarding @GetGeneratedKeys, but still it does not seem to return a ResultSet with the key, It works using plain JDBC, but i'll have to reimplement all the code and it's a no go for my project and for using jDBI in other projects .
//@Test
public void oldJDBCInsertTest(){
DataSource ds = DBCPDataSourceFactory.getDataSource();
try {
Connection con=ds.getConnection();
PreparedStatement prepStmt;
prepStmt = con.prepareStatement("INSERT INTO INTERACTION_TYPE (ID, LOGICALNAME, REGULAREXP) "
+ "VALUES (NEXT VALUE FOR SEQ_INTERACTION_TYPE, 'test', 'test')", new String[]{"ID"});
prepStmt.executeUpdate();
ResultSet rs = prepStmt.getGeneratedKeys();
while (rs.next() == true)
{
System.out.println(rs.getInt(1));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
I've attached an Eclipse debug variable tab, wich shows returningGeneratedKeys=true but the empty result set.
I'm using the following jars for db2
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>4.19.26</version>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc_license_cu</artifactId>
<version>3.64.96</version>
</dependency>
and the following jar for jdbi:
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
<version>2.62</version>
</dependency>
Thanks