Skip to content

Instantly share code, notes, and snippets.

@maikelsperandio
Created October 8, 2013 18:21
Show Gist options
  • Save maikelsperandio/6889130 to your computer and use it in GitHub Desktop.
Save maikelsperandio/6889130 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