1 package org
.codehaus
.groovy
.grails
.orm
.hibernate
.support
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.hibernate
.Hibernate
;
6 import org
.springframework
.beans
.BeanWrapperImpl
;
7 import org
.springframework
.beans
.BeansException
;
9 import java
.beans
.PropertyDescriptor
;
10 import java
.lang
.reflect
.Method
;
13 * BeanWrapper implementaion that will not lazy initialize entity properties.
15 public class HibernateBeanWrapper
extends BeanWrapperImpl
{
16 // ------------------------------ FIELDS ------------------------------
18 private static final Log log
= LogFactory
.getLog(HibernateBeanWrapper
.class);
20 // --------------------------- CONSTRUCTORS ---------------------------
22 public HibernateBeanWrapper() {
25 public HibernateBeanWrapper(boolean b
) {
29 public HibernateBeanWrapper(Object o
) {
33 public HibernateBeanWrapper(Class aClass
) {
37 public HibernateBeanWrapper(Object o
, String s
, Object o1
) {
41 // ------------------------ INTERFACE METHODS ------------------------
44 // --------------------- Interface PropertyAccessor ---------------------
47 * Checks Hibernate.isInitialized before calling super method.
49 * @param name target property
50 * @return null if false or super'name value if true
51 * @throws BeansException
53 public Object
getPropertyValue(String name
) throws BeansException
{
54 PropertyDescriptor desc
= getPropertyDescriptor(name
);
55 Method method
= desc
.getReadMethod();
56 Object owner
= getWrappedInstance();
58 if (Hibernate
.isInitialized(method
.invoke(owner
, null))) {
59 return super.getPropertyValue(name
);
61 } catch (Exception e
) {
62 log
.error("Error checking Hibernate initialization on method " +
63 method
.getName() + " for class " + owner
.getClass(), e
);