What’s wrong in this code?
I have a bound to a class “Fornitore fornitore” property this way:
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Fornitore.class, new PropertyEditorSupport() {
@Override
public void setAsText(String fornitoreId) throws IllegalArgumentException {
logger.info("FORNITORE:: setValue");
setValue((Fornitore) fornitoreService.getFornitore(fornitoreId));
}
@Override
public String getAsText() {
logger.info("FORNITORE:: getValue");
if (getValue() == null) {
return "";
} else {
return ((Fornitore) getValue()).getRagioneSociale();
}
}
});
}
Ends up with:
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at it.trew.prove.model.beans.Fornitore_$$_javassist_0.getRagioneSociale(Fornitore_$$_javassist_0.java)
at it.trew.prove.web.controllers.ScadenziarioController$1.getAsText(ScadenziarioController.java:56)
I’m not sure I see any relation between the spring DataBinder above and the Hibernate Session error below. I see nothing obviously wrong with the data binder, but it doesn’t have anything to do with starting a hibernate session.