JSF Validations & Hibernate cglib

Hi,

I'm having some trouble with using Hibernate with JSF.

When using hibernate, lazy loaded.

The problem is that i now have a CGLIB-enhanced version of one of my domain objects. The value of which is to be compared to a list of selectitems.

As it turns out, JSF tries casting my normal objects to a version of those EnhancedObjects, which gives me an IllegalArgumentException because of course the Parent class (ConfigProfile) cannot be cast to one of it's children (ConfigProfile$$EnhancerByCGLibxxx$$)

Has anyone ever come across this problem, and knows how to handle it ?

Thanks in advance !

Jeroen

My Exception :

12-jan-2007 11:18:14 com.sun.faces.lifecycle.ProcessValidationsPhase execute

WARNING: Cannot convert com.watchtalk.web.businessobject.ConnectProfile@966905 of type class com.watchtalk.web.businessobject.ConnectProfile to class com.watchtalk.web.businessobject.ConnectProfile$$EnhancerByCGLIB$$b8f981a2

java.lang.IllegalArgumentException: Cannot convert com.watchtalk.web.businessobject.ConnectProfile@966905 of type class com.watchtalk.web.businessobject.ConnectProfile to class com.watchtalk.web.businessobject.ConnectProfile$$EnhancerByCGLIB$$b8f981a2

at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:367)

at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:52)

at javax.faces.component.UISelectOne.matchValue(Unknown Source)

at javax.faces.component.UISelectOne.validateValue(Unknown Source)

at javax.faces.component.UIInput.validate(Unknown Source)

at javax.faces.component.UIInput.executeValidate(Unknown Source)

at javax.faces.component.UIInput.processValidators(Unknown Source)

at javax.faces.component.UIForm.processValidators(Unknown Source)

at javax.faces.component.UIComponentBase.processValidators(Unknown Source)

at javax.faces.component.UIViewRoot.processValidators(Unknown Source)

at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(Unknown Source)

at com.sun.faces.lifecycle.LifecycleImpl.phase(Unknown Source)

at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)

at javax.faces.webapp.FacesServlet.service(Unknown Source)

[2268 byte] By [oeniea] at [2007-11-26 14:56:08]
# 1
Do you have any progress with the this issue yet? I encounter the same exact problem and am desperate for a solution now.Thanks.
jaylina at 2007-7-8 8:44:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

In my case the exception was from expr.setValue(el, bo), where the Object before was a CGLIB-Proxy and the new Class wasn't. The Solution was to set the value NULL, before set the new Object.

FacesContext context = FacesContext.getCurrentInstance();

ELContext el = context.getELContext();

ExpressionFactory ef = context.getApplication().getExpressionFactory();

ValueExpression expr = ef.createValueExpression(el, "${Businessobject}", Businessobject.class);

Service service = (Service) getBeanFromContext(service);

Businessobject bo = service.createBusinessobject();

expr.setValue(el, null);

expr.setValue(el, bo);

I hope this will be helpful for you.

th.k.a at 2007-7-8 8:44:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...