Skip to content

Instantly share code, notes, and snippets.

@hferentschik
Created August 12, 2011 15:08
Show Gist options
  • Save hferentschik/1142243 to your computer and use it in GitHub Desktop.
Save hferentschik/1142243 to your computer and use it in GitHub Desktop.
extractPropertId
private Serializable extractProperId(Work<T> work) {
T entity = work.getEntity();
// 1) entity is null for purge operation, which requires to trust the work id
// 2) types mapped as provided id require to use the work id
// 3) when Hibernate identifier rollback is used && this identifier is our same id source, we need to get the value from work id
if ( entity == null
|| documentBuilder.requiresProvidedId()
|| ( work.isIdentifierWasRolledBack() && documentBuilder.isIdMatchingJpaId() ) ) {
return work.getId();
}
else {
// return documentBuilder.getId( entity );
Serializable id = documentBuilder.getId( entity );
if ( id != null ) {
return id;
}
else {
return work.getId();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment