public Number getKey() {
if (this.keyList.size() == 0) {
return null;
}
if (this.keyList.size() > 1 || this.keyList.get(0).size() > 1) {
throw new DataAccessException("The getKey method should only be used when a single key is returned. "
+ "The current key entry contains multiple keys: " + this.keyList);
}
Iterator<Object> keyIter = this.keyList.get(0).values().iterator();
if (keyIter.hasNext()) {
Object key = keyIter.next();
if (!(key instanceof Number)) {
throw new DataAccessException("The generated key is not of a supported numeric type. "
+ "Unable to cast [" + (key != null ? key.getClass().getName() : null) + "] to ["
+ Number.class.getName() + "]");
}
return (Number) key;
} else {
throw new DataAccessException("Unable to retrieve the generated key. "
+ "Check that the table has an identity column enabled.");
}
}