Sunday, December 28, 2008

Saturday, December 20, 2008

Hibernate issue in Grails

I have an object Person that contains many Resume objects. The application is for managing your personal work information and presenting that in multiple resume formats.  This issue is that when using GORM in Grails I want the main layout to list all the person's available resumes along the side bar of the application. No problem except that sitemesh the framework used by Grails to control site layout and templating explodes with a Lazy Load exception when trying to render the list of resumes from the current logged in person object.  I read a little and found out that the OpenSessionInViewFilter opens a session and binds it to the thread, like expected, but before sitemesh has completed rendering the view it appears that the clean up of closing the Hibernate session has already occured causing the lazy load problem. 

No problem a few google searches later and I have some code that looks like:

import org.hibernate.FetchMode as FM 

def c = Person.createCriteria()
Person person = c.get{
eq("username",params.username)
fetch("resumes",FM.EAGER)
}

Turns out this works fine, however when using this invoking this after creating a new resume. So the scenario of walking through a series of screens to create a new resume and then going back home to the user's home page where the resumes are displayed as links in the sidebar again blows up with the Object already in session.

The solution to this issue is to not call save at the end of the flow for creating a resume but rather call the merge method this will clean up the Hibernate session and allow the above EAGER fetch to proceed without additional problems.

if( !resume.merge() ){
// do something
}  


Friday, December 19, 2008

Changing the Default JDK for Netbeans 6.5 on the Mac OS X platform

I need to jot this down before I lose it.  So here it goes.

1. ) From a terminal window go to 
/Applications/Netbeans/Netbeans 6.5.ap/Contents/Resources/NetBeans/etc/

2. ) open up the netbeans.conf file and edit the following line to look like 
netbeans_jdkhome=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

Thats it!! 
I hope that helps you. Restart Netbeans if you haven't already.