Database dependent ID generation going from hibernate 2 to 3

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

If you need an identity generator that combines the assigned and the IDENTITY one, check out this one:

public class AssignedIdentityGenerator
    extends IdentityGenerator {
 
    @Override
    public Serializable generate(SessionImplementor session,
        Object obj) {
        if(obj instanceof Identifiable) {
            Identifiable identifiable = (Identifiable) obj;
            Serializable id = identifiable.getId();
            if(id != null) {
                return id;
            }
        }
        return super.generate(session, obj);
    }
}

This one works with Hibernate 5, which is probably what you should migrate to.

For more details, check out this article.