Skip to content

Instantly share code, notes, and snippets.

@geosava
Forked from maikelsperandio/unproxy.java
Created October 19, 2015 12:46
Show Gist options
  • Save geosava/554a3cdebd70108e2e20 to your computer and use it in GitHub Desktop.
Save geosava/554a3cdebd70108e2e20 to your computer and use it in GitHub Desktop.
Method to unproxy an object from hibernate proxy
@SuppressWarnings("unchecked")
protected T unproxy(T entity){
if (entity == null) {
return null;
}
if (entity instanceof HibernateProxy) {
try {
Hibernate.initialize(entity);
} catch (ObjectNotFoundException e) {
return null;
}
entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation();
}
return entity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment