2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
;
12 import org
.hibernate
.envers
.entities
.mapper
.relation
.lazy
.proxy
.MapProxy
;
13 import org
.hibernate
.proxy
.HibernateProxy
;
14 import org
.hibernate
.proxy
.LazyInitializer
;
16 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
17 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 * TODO merge with {@link HibernateProxyHelper}
22 * This class extends the {@link org.hibernate.proxy.HibernateProxyHelper}.
23 * Since {@link org.hibernate.proxy.HibernateProxyHelper} is final the {@link #getClassWithoutInitializingProxy(Object)}
24 * is repeated here for convenience.
26 * @author a.kohlbecker
28 public class HibernateProxyHelperExtended
{
31 * Get the class of an instance or the underlying class
32 * of a proxy (without initializing the proxy!). It is
33 * almost always better to use the entity name!
36 public static Class
getClassWithoutInitializingProxy(Object object
) {
37 if (object
instanceof HibernateProxy
) {
38 HibernateProxy proxy
= (HibernateProxy
) object
;
39 LazyInitializer li
= proxy
.getHibernateLazyInitializer();
40 return li
.getPersistentClass();
43 return object
.getClass();
48 * Unwrap the target instance from the proxy.
50 public static Object
getProxyTarget(Object object
){
51 if(object
instanceof HibernateProxy
) {
52 LazyInitializer lazyInitializer
= ((HibernateProxy
)object
).getHibernateLazyInitializer();
53 return lazyInitializer
.getImplementation();