3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * 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
.apache
.log4j
.Logger
;
13 import org
.hibernate
.HibernateException
;
14 import org
.hibernate
.collection
.spi
.PersistentCollection
;
15 import org
.hibernate
.envers
.entities
.mapper
.relation
.lazy
.proxy
.CollectionProxy
;
16 import org
.hibernate
.envers
.entities
.mapper
.relation
.lazy
.proxy
.MapProxy
;
17 import org
.hibernate
.proxy
.HibernateProxy
;
19 import eu
.etaxonomy
.cdm
.persistence
.dao
.AbstractBeanInitializer
;
22 * @author a.kohlbecker
26 //@Component("defaultBeanInitializer")
27 public class HibernateBeanInitializer
extends AbstractBeanInitializer
{
29 public static final Logger logger
= Logger
.getLogger(HibernateBeanInitializer
.class);
32 * @see eu.etaxonomy.cdm.persistence.dao.AbstractBeanInitializer#initializeInstance(java.lang.Object)
35 public Object
initializeInstance(Object bean
) {
37 return HibernateProxyHelperExtended
.getProxyTarget(bean
);
40 public static void initialize(Object proxy
) throws HibernateException
{
41 if ( proxy
== null ) {
44 else if ( proxy
instanceof HibernateProxy
) {
45 ( ( HibernateProxy
) proxy
).getHibernateLazyInitializer().initialize();
46 } else if ( proxy
instanceof PersistentCollection
) {
47 ( ( PersistentCollection
) proxy
).forceInitialization();
48 } else if(proxy
instanceof CollectionProxy
) {
49 ( ( CollectionProxy
) proxy
).isEmpty(); // checkInit is protected, unfortunately;
50 } else if(proxy
instanceof MapProxy
) {
51 ( ( MapProxy
) proxy
).isEmpty(); // checkInit is protected, unfortunately;