Grails, Hibernate Event Listeners and ArrayStoreException

The Problem

Trying to register few Hibernate event listeners from plugin, But some how, registering the custom event listeners causes ArrayStoreException at runtime.

In plugin class

 def doWithSpring = {
	hibernateEventListeners(HibernateEventListeners) {
		listenerMap = ['save':sanitizeHtmlListner]

Listener class

class SanitizeHtmlListner implements SaveOrUpdateEventListener {


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization o
f bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
ry': Invocation of init method failed; nested exception is java.lang.ArrayStoreException
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:391)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initi
alization of bean failed; nested exception is


No solution is known,

This is a bug in Grails, which will not let you register SaveAndUpdateListener,  and if you do, you get this error. if you try with pre-insert, pre-update listeners it should work. I don’t know what other listeners are affected.



A simple grails CMS inspired from drupal

I am working on creating a new CMS based on grails. The purpose is to use it for a new site I am going to launch in near future.

I really like drupal, and I want not all but similar features in my CMS.

  • Create/Edit/View/Delete nodes
  • Spaces (eg news, announcements)
  • Blocks
  • Regions
  • URL aliases
  • Make creating custom content type easy
  • Comments
  • Full text search
  • File upload

No plugin architecture, revisions or full support for themes initially.

Why not weceem or any other existing CMS

Just because I want to develop my own so that I understand it and i have full flexibility.

If you have any comments/suggestions please comment here.

The future of Java servlets and web applications – JSR 340

You must be aware of the Servlet 3.0 spec,  and what cool things it brings to the java web development. If not, you can read it here Introduction to servlet 3.0 new features. Servlet 3.0 was released as part of the JavaEE6 and brings many exciting features like Annotations, web framework playability, built in file upload support and comet support. That’s the present of java web applications, many containers like Tomcat 7.x and Glassfish V3 supports Servlet 3.0 Spec.

The future of servlets

There’s yet more goodness to come to servlets , A new specification request, JSR 340 has been submitted, that will develop the new version 3.1 of java servlets.  The JSR 340 will be part of the JavaEE 7

Here’s the main theme of the Servlet 3.1 spec

  • Cloud support : The main theme of the JavaEE7 would be to improve the platform for cloud
  • Multi tenancy support : Just like cloud, multi tenancy are becoming quite popular with the SAAS applications. So in the 3.1 version of the servlets, we will see a built in support for multi tenancy that will consider the things like security, session state, resources and other isolation requirements.
  • Improved support for asynchronous request processing.
  • Utilize the Java EE concurrency APIs for asynchronous support.
  • Security improvement based on the   security enhancements in servlet 3.0 spec.
  • Take the advantage of HTML 5,  support for web sockets.

Related links

Does java miss a good HTML sanitizer ?

I have been looking for a good Java HTML sanitizer, that would let me sanitize user input based on a whitelist, and would escape other things. There are some examples here and there but none seems so complete as PHP, Ruby, Python and Pearl.
Does java really miss a robust HTML sanitizer ?
Do you know any good open source HTML sanitizer for java !
I have released a grails plugin html-cleaner Which is a whitelist based html sanitizer – based on Jsoup

Deleted MySql root user accidently? Recreate root account

Deleted MySql root user accidently?

Follow the steps recreate the root user.

  1. If mysql service is already running, stop it.
  2. Open the command prompt and goto MYSQL_HOME/bin directory.
  3. Run following commands

> mysqld --skip-grant-tables

Then start mysql console

> mysql –u=root

Then run following commands



Then restart the mysql service and you are done.

wireframesketcher – You will love this plugin

When some one said ‘A picture is worth a thousand words’, He said true. During the early phase of the projects, I frequently have to create screen mockups and send to client for review. I have been always doing this by hand (though i knew about the tools). But when I found about the wireframesketcher I decided to give it a try, mainly because It worked within eclipse, and I am really quite satisfied by the results that now I will be using it for all the future projects.

If you are a developer and use eclipse, and you need to create screen mockups, then you must try this plugin.  Get the  trial version of the plugin.

Wait for a complete review…. I will update with some example screens

mvn eclipce:eclipse gives error – Request to merge when ‘filtering’ is not identical

Description: You get the error Request to merge when ‘filtering’ is not identical when running mvn eclipse:eclipse on a maven project

Root cause: It’s because of the change in maven eclipse plugin

solution: try this

mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse

Vote for google app engine Maven plugin

Yes, Just like you, I am also looking for maven support in GAE.

There is an unofficial GAE maven plugin here. But  It would be great if google release an official maven plugin and publish artifacts to central maven repository.

Vote here if you are looking for maven support in GAE

Update: Finally My trick did the work. I posted link to this issue on mailing lists and blogs related to Java/app engine on January 7.  Since then more than 100 people have voted for the issue.  And the issue is now accepted by google.

Now we can hope for a official appengine maven plugin in near future.

Update 27-DEC-2010

Congratulations !
I just noticed that the issue has been fixed. App Engine 1.3.7 is now in Maven central and future versions will be pushed to central after each release.

See the link for How to use Maven with google plugin for eclipse.

Freemarker sucks, dependency on javax.swing, Wouldn’t run on GAE

I would say freemarker sucks.
Yes it does. A template engine has dependency on javax.swing !!
Isnt that surprising?

Today, I was trying to deploy a Stripe/Freemarker hello world app on GAE and I got following.

java.lang.NoClassDefFoundError: javax.swing.tree.TreeNode is a restricted class. Please see the Google App Engine developer's guide for more details.
at freemarker.core.TextBlock.isIgnorable(
at freemarker.core.TemplateElement.postParseCleanup(
at freemarker.core.MixedContent.postParseCleanup(
at freemarker.core.FMParser.Root(
at freemarker.template.Template.(
at freemarker.cache.TemplateCache.loadTemplate(
at freemarker.cache.TemplateCache.getTemplate(
at freemarker.cache.TemplateCache.getTemplate(
at freemarker.template.Configuration.getTemplate(
at freemarker.core.Environment.getTemplateForInclusion(
at freemarker.core.Include.accept(
at freemarker.core.Environment.visit(
at freemarker.core.MixedContent.accept(
at freemarker.core.Environment.visit(
at freemarker.core.Environment.process(
at freemarker.template.Template.process(
at freemarker.ext.servlet.FreemarkerServlet.process(
at freemarker.ext.servlet.FreemarkerServlet.doGet(

Yes, you can not use freemarker on GAE, at least not without hacking it.

I found a patch here, seems that it would solve above exception.

Who knows that it wouldn’t have dependency on more classes. we can just hope for good.

Nope, above solution isn’t going to work all the time.
I had a quick look at the code, I think that the culprit is here.

abstract public class TemplateElement extends TemplateObject implements TreeNode

From the code, it seems that TemplateElement implements TreeNode
Just because it needs contract similar to TreeNode but it does not have any thing to do with swing API. (You already knew that)
Instead of implementing TreeNode, author could have created a new interface which exposes similar contract.

Do we implement any interface which exposes similar contract that we need? Context matters. EJB spec has some interface with methods that a servlet want doesn’t mean it can be implemented by a servlet.

Hope, devs would fix it in next release.
The issue is discussed in mailing list here

At the end, I would like to say, I like freemarker and that’s why I wrote even a hello world stripe application in freemarker.

Update 26/03/2010

Friends at freemarker has released a Freemarker GAE prerelease which can be downloaded here. It should work on GAE.  Any one interested in running freemarker on GAE should try it and report issues if any.

see  freemarker on GAE too.

update 28/04/2010

No, still freemarker-gae-pre2 will not work on GAE, I have tested it on GAE 1.3.2.  You will get one or both of the following exceptions

java.lang.VerifyError: (class: freemarker/ext/jsp/FreeMarkerJspApplicationContext, method: signature: ()V) Incompatible argument to function


java.lang.NoClassDefFoundError: Could not initialize class freemarker.ext.jsp.PageContextFactory

See this thread and this thread . The issue has been reported to GAE team here vote for it.

Waiting for the freemarker or GAE team to come up with explanation/solution.

DDD Without any ORM tool, is it possible !!

DDD Without any ORM tool, is it possible !!

When reading DDD book and trying out it on a sample project that doesn’t use any ORM tool. I came across a question, is it possible to strictly implement DDD without any ORM tool !

Is there any one here who has implemented DDD on any real project that doesn’t use any ORM but pure JDBC only?

Before few days, I had a question on how to paginate and lazy load non root objects

Various alternatives and answers came up, but why do I need to find an alternative ! I don’t need to do any thing specific when using hibernate and just depend on the lazy loading support provided by it.

I want to paginate because I don’t want to load entire graph of few thousand objects into memory and when using hibernate and lazy loading that’s not an issue. With NO-ORM, I can achieve similar thing by hand coding dynamic proxies for lazy loading, and let repositories handle it.

However the second point is more important.

The second question is related to repositories, transitive persistence and dirty checking.
The DDD book (Chapter 6 – repositories) says “it allows freely switching persistence strategies at any time.”

Is it really possible and easy without modifying domain at all !

How about dirty checking and persistence by reachability without any ORM ?
When you save/update an aggregate root, entire graph should be saved and/or updated. How the repository will determine which objects are modified/inserted or deleted?

Probably you will need some thing like isNew() isStale() inside every entities to find out if it needs to be included as part of insert/update. And set flags when ever any setter or any other method changes state of the object. I have seen similar thing in a project which uses DDD with JDBC.

Several answers came up

Get the data from the database and determine updates, deletes, and inserts in code.

This may not be the best routine, but I use a boolean flag to determine what needs persisted. I have a property in each entity called .IsDirty. When anything inside the aggregate root needs persisted, I use the root’s repository and call root.Persist and I go through the root. The root repository then loops through each entity and tests the .IsDirty flag

Do you see any pattern in this answers ?

  • It says either modify your domain model or write some thing like your little ORM to do this things.
  • That says DDD is tightly bound to ORM and “Freely switching of persistence technology” means switching from one ORM to another (it could be your own).

How about Delete?
Lets say root has a collection of associated entities (In my example MessageFolder has Collection of messages)

I can do some thing like
MessageFolder.remove(Message message)

That would remove message from the collection. When saving the MessageFolder, how the repository can find out what messages are deleted? Either message folder need to maintain a collection of removed messages or repository need to have old message folder for comparision. The first option forces me to modify MessageFolder, that mean domain model became aware of underlying persistence technology. The second option would need to load old entity which would affect performance.

It might be possible to switch to ORM from a No-ORM application but what about switching to NO-ORM from ORM ! Does that mean I will have to add custom behavior to my entities to figure out weather they are new or modified or deleted.

These are few questions that I am not able to answer my self and seeking some expert thoughts. If you have done DDD for a real life project that does not use any ORM, please comment.

Some people said CQRS and Domain events can solve this problem, however I am yet to find a working example.

There is a sample DDD application created by DDD community. The sample application uses Hibernate in persistence layer.
I wish some day DDD community would release a sample application that works on pure JDBC. As still there are lots of companies who use bare JDBC and no ORM at all.

Look at the thread