Skip to content

Commit

Permalink
revert handleLazyProxy method changes. Keep the old behaviour for com…
Browse files Browse the repository at this point in the history
…patibility reasons.
  • Loading branch information
lhotari committed May 5, 2013
1 parent f2dc0c8 commit 8ef8d2b
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -41,11 +41,30 @@ class HibernateUtils {

static final Logger LOG = LoggerFactory.getLogger(HibernateUtils)

static final Closure LAZY_PROPERTY_HANDLER = { String propertyName ->
def propertyValue = PropertyUtils.getProperty(getDelegate(), propertyName)
if (propertyValue instanceof HibernateProxy) {
propertyValue = GrailsHibernateUtil.unwrapProxy(propertyValue)
}
return propertyValue
}

/**
* Overrides a getter on a property that is a Hibernate proxy in order to make sure the initialized object is returned hence avoiding Hibernate proxy hell.
*/
static void handleLazyProxy(GrailsDomainClass domainClass, GrailsDomainClassProperty property) {
// return lazy proxies
String propertyName = property.name
String getterName = GrailsClassUtils.getGetterName(propertyName)
String setterName = GrailsClassUtils.getSetterName(propertyName)

GroovyObject mc = (GroovyObject)domainClass.metaClass

mc.setProperty(getterName, ((Closure)LAZY_PROPERTY_HANDLER.clone()).curry(propertyName))
mc.setProperty(setterName, { PropertyUtils.setProperty(getDelegate(), propertyName, it) })

for (GrailsDomainClass sub in domainClass.subClasses) {
handleLazyProxy(sub, sub.getPropertyByName(property.name))
}
}

static void enhanceSessionFactories(ApplicationContext ctx, GrailsApplication grailsApplication, Object source = null) {
Expand Down

0 comments on commit 8ef8d2b

Please sign in to comment.