Hibernate in CF
I know Joe posted on this recently, but is anyone using Hibernate for real as the persistence mechanism for CF apps? I know Kurt has also talked about persisting VO's from CF to Hibernate, but has anyone got a real world app working end to end?
If so, are you using Kurts code for persisting the CFC VO’s? How do you handle lazy loading in CF using Hibernate? Are there any event notifications in Hibernate and how hard is it to “handle” them in ColdFusion? How do you handle the errors returned by Hibernate? Anyone got any sample code to share beyond the single listing by Joe and the one by Kurt? Any performance issues? And issues logging/debugging Hibernate issues?
Comment below or join the Yahoo group and let us know what you've been doing!



Most interesting stuff is how CFCs are persisted - when passing CFC instance to load(), update(), save(), saveOrUpdate() or delete() method of the wrapper it checks if corresponding Java class exists. If not CF generates Java source file, generates the class. It is quite fast process and done only if class file doesn't exist.
But on the other hand - when considering Hibernate why would I consider CF? When all I need is few if statements, some calculation I would not use CF for that when using Hibernate. When I need generate PDF files or call webservices then of course yes.
Thanks for the input!
Can you remember what specifically were the issues that Joe was highlighting?
Kind of. We model the entire domain layer in Java and just expose a service API, so CF isn't directly talking to Hibernate.
>If so, are you using Kurts code for persisting the CFC VO’s?
Nope.
>How do you handle lazy loading in CF using Hibernate?
As in keeping the session open? We use Spring, and wrap each request in Spring's openSessionInViewInterceptor. You can also configure this interceptor into JRun, but on CF Standard that means every application will use the same session factory.
> Are there any event notifications in Hibernate and how hard is it to “handle” them in
> ColdFusion?
Not an issue - they stay within the domain layer.
>How do you handle the errors returned by Hibernate?
In theory we should translate and rethrow exceptions on the Java side, but at the moment we just catch them, e.g. catch (org.hibernate.validator.InvalidStateException e) {}
>Anyone got any sample code to share beyond the single listing by Joe and the one by Kurt?
<cfscript>
context = CreateObject("Java", "org.springframework.context.support.ClassPathXmlApplicationContext");
contextPaths = ["config/applicationContext.xml","config/datasource.xml"];
context.init(contextPaths);
service = context.getBean("UserService");
user = service.getUser("jmetcher");
up = user.getUserProfile();
</cfscript>
<cfoutput>#user.getId()# #up.getFirstName()# #up.getLastName()#</cfoutput>
Obviously we'd cache the context in the Application scope. Also, I've left out the interceptor code - it's really just plumbing. Beyond that, all the interesting stuff happens on the Java side, which is just pretty standard Spring/Hibernate.
>Any performance issues?
Orders of magnitude faster than a CF domain layer.
> And issues logging/debugging Hibernate issues?
No. Being able to unit test in Eclipse with JUnit is pretty sweet. If something does go wrong when deployed to the app server, the exception log tells all. Then 99% of the time we just go back to offline unit testing to debug the problem.
Jaime