small medium large xlarge

Back to: All Forums  Grails
Generic-user-small
13 Dec 2009, 18:12
Gregor Skubacz (2 posts)

Hi,

I have some problems with the examples. If I try to add or change the volunteers of an event or try to assign an user to a task I got a ClassCastException. I’m using grails 1.1.2 and mysql 5.1. What is going wrong?

Changing a volunteer: Error 500: java.lang.ClassCastException: TekUser$__clinit__closure1 cannot be cast to java.util.Map Servlet: grails URI: /TekDays/grails/tekEvent/update.dispatch Exception Message: TekUser$__clinit__closure1 cannot be cast to java.util.Map Caused by: java.lang.ClassCastException: TekUser$__clinit__closure1 cannot be cast to java.util.Map Class: TekEventController At Line: [69] Code Snippet: 68: } 69: tekEventInstance.properties = params 70: if(!tekEventInstance.hasErrors() && tekEventInstance.save()) {

Assigning a user to a task: Error 500: java.lang.ClassCastException: TekEvent$__clinit__closure1 cannot be cast to java.util.Map Servlet: grails URI: /TekDays/grails/task/update.dispatch Exception Message: TekEvent$__clinit__closure1 cannot be cast to java.util.Map Caused by: java.lang.ClassCastException: TekEvent$__clinit__closure1 cannot be cast to java.util.Map Class: TaskController At Line: [68] Code Snippet: 67: } 68: taskInstance.properties = params 69: if(!taskInstance.hasErrors() && taskInstance.save()) {

Thanks Gregor

Generic-user-small
16 Dec 2009, 09:44
Cam MacRae (3 posts)

I’ve got the same error with Grails 1.1.2 irrespective of which database I use. The code generated by grails @generate-controller Task@ is identical to the downloaded code.

Dklein_tiny_pragsmall
16 Dec 2009, 15:42
Dave Klein (34 posts)

I haven’t tried any of the book code with Grails 1.1.2. In fact, I haven’t tried 1.1.2 at all. :-) I will try it out and see if I can tell what’s happening.

Dave

Generic-user-small
17 Dec 2009, 01:19
Cam MacRae (3 posts)

See the following issue: http://jira.codehaus.org/browse/GRAILS-5445

Generic-user-small
17 Dec 2009, 03:35
Cam MacRae (3 posts)

Upgrading to 1.2.0.RC2 and downgrading to 1.1.1 both resolved this issue for me.

Me_pragsmall
17 Dec 2009, 21:47
David Kowis (6 posts)

I’ve run into the same problem in a couple of places: * replying to a message in chapter 7’s example.

I tried the workaround in the GRAILS-5445 issue and it doesn’t even work thanks to being unable to find WebApplicationContextUtils as a property of BootStrap (which I know it’s not. Probably an import I’ve got to figure out)

sigh

EDIT: figured out a full solution to it that will keep you (and me :) ) coding along: Add this import ` import org.springframework.web.context.support.WebApplicationContextUtils `

Then add this code to the top of the init closure

		//GRAILS BUG 5445 -- WORKAROUND
		def ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)

		for(d in ctx.getBean("grailsApplication").domainClasses) {
			def domain = d
			domain.clazz.metaClass.static.get = { Serializable id ->
				def obj = ctx.getBean("sessionFactory").currentSession.get(domain.clazz,id.toLong())
				if(obj instanceof org.hibernate.proxy.HibernateProxy) {
					obj = obj.getHibernateLazyInitializer().implementation
				}
				return obj
			}
		}
		//END WORKAROUND FOR GRAILS BUG 5445

This workaround comes from the bug, but the bug didn’t include the import and it wasn’t trivial to figure out (or I’m just not so fast :) )

Generic-user-small
19 Dec 2009, 05:29
Gregor Skubacz (2 posts)

Thank you for the hints. The upgrade to 1.2.0.RC2 resolved this issue for me too.

Generic-user-small
24 Dec 2009, 14:01
Mark Hawkins (1 post)

I also experienced similar problems with Grails 1.1.2 and ‘Task’ update actions - an upgrade to Grails 1.2.0 seems to have solved the problem. Thanks.

You must be logged in to comment