I am tasked with upgrading the hibernate on one of our java apps. It currently uses hibernate 2 and I am first trying to get to 3. I am new to hibernate and am having trouble reworking the id generator. The app has a db2 database & the OIG.V_UNIQUE_KEY table has 1 column & 1 record that changes with each added record to the database.
Here is the current code:
public class UniqueKeyGenerator implements IdentifierGenerator, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public UniqueKeyGenerator() {
super();
}
public Serializable generate(SessionImplementor session, Object object)
throws SQLException, HibernateException {
Long assignedid = (Long)((Entity)object).getAssignedId();
if (assignedid != null)
return assignedid;
PreparedStatement st = session.getBatcher().prepareStatement("select UNIQUE_KEY_ID from OIG.V_UNIQUE_KEY");
try {
ResultSet rs = st.executeQuery();
final Number result;
try {
rs.next();
//result = IdentifierGeneratorFactory.get(rs, Long.class);
result = (Number) IdentifierGeneratorFactory.get(rs, new LongType(), session, object);
}
finally {
rs.close();
}
return result;
}
catch (SQLException sqle) {
JDBCExceptionReporter.logExceptions(sqle);
throw sqle;
}
finally {
session.getBatcher().closeStatement(st);
}
}
}
The get method that we are using is now deprecated and I have been unable to find a workable solution. I have searches some new id generator strategies, but have not been able to find one that I could get working. Any help would be greatly appreciated. Thanks