Using Spring Batch in Grails applications

In one of my grails projects we are using Spring Batch for processing huge amounts of data. We are processing 100000 database entries in one run. When using HibernatePagingItemReader or HibernateCursorItemReader we ran into OutOfMemory errors. Using the Eclipse Memory Analyzer I quickly found the reason for this behavior. When starting the Spring Batch Job via the JobLauncher from a Grails Quartz Plugin Job it creates a HibernateSession per default. Even if the Spring Batch jobs handle the HibernateSession correct by fetching only a few items and committing small blocks of elements per transaction all the read items are still held by outer HibernateSession of the Quartz Job. Read more →

MySQL Row size too large

Lately a customer I am helping to build a Grails application had an issue with creating tables in MySQL. They got the following error message when Hibernate tried to create the tables for their domain model: Column length too big for column 'text' (max = 21845); use BLOB or TEXT instead The reason was that the maxSize constraint of this property was set to 40000 and Hibernate tried to create a VARCHAR(40000) column in the MySQL table. Read more →

Splitting Spring configuration in Grails applications

My colleague Andre wrote an interesting post about this topic already and I have to do a follow up. In one of our projects we followed the assumptions Andre made and we found out that there are some things you might be careful not to stumble over them. First when experimenting with Spring bean configurations in your Grails application it is useful to change the log level for org.codehaus.groovy.grails.commons to at least warning level. Read more →

Default naming strategies with Grails an plain Hibernate

Last year (damn so long ago? seems like last week) I wrote a post about naming strategies and reusing an existing Hibernate domain model in a Grails app. I stumbled across this because I created a Grails application that is used as a “back office” management application for our time tracking product timr.com the uses the existing Hibernate domain model classes from the Spring application. There has also been a blog post on the official Springsource blog about this where I made a comment. Read more →

Using groovy for scripting linux servers

Today I wanted to add some more graphs to our munin server monitoring. One graph should check the ftp backup server and plot how many of the available 100GB space is already used. Another graph should display the current sessions on out tomcat servers. The munin documentation should how easy it is to create a plugin but I am not an advanced shell script programmer so I gave groovy a try. Read more →

Be careful when reusing Hibernate domain model in Grails

In one of my projects I am using Grails to create a simple crud management UI for an Spring MVC app. Because Grails allows to reuse the existing Hibernate domain model of the Spring app this saved a lot time. Last week I suddenly found out that Grails was using a different naming strategy when mapping the model to the database. In my case I wanted to let Grails create the tables for the Spring Security plugin so I activated the hbm2ddl update. Read more →

BlackBerry Development Environment for Mac OS X

For me as developer that creates apps for the BlackBerry Java environment one of the best news of this years Devcon was, that the Java development tools are now available, as a first tech preview, for Mac OS X. I switched to Mac OS three months ago and the only reason for firing up the VM were the BlackBerry tools. So I downloaded the tools when the were published and installed them. Read more →

Using column alias in GORM criterias

Last week I tried to create GORM criteria that shows from which countries the addresses stored in a table were. The SQL for this would look something like this: select c.code, count(*) from Address a left outer join Country c on a.country=c.id group by c.code Now I wanted to sort the results with the country the most addresses were from on top. This SQL would look like: select c.code, count(*) as co from Address a left outer join Country c on a. Read more →

Create executable jar package with dependencies

Lately I wrote myself some small GUI tools using Groovy’s SwingBuilder. To “install” them in my system I wanted to create a single JAR file containing all the required dependencies. Using the following maven plugin configuration it was very easy to achieve that: <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> Running the mvn assembly:assembly command created the desired JAR file containing the MANIFEST file that runs the right Class on double clicking the JAR. Read more →

Equals and HashCode and Hibernate

In one of my current consulting projects the topic of implementing equals and hashCode in Hibernate domain model classes was discussed again so I decided to write down how I deal with that in my projects. First I encourage every Java developer to read chapter 3 of Effective Java from Joshua Bloch - which is available online here (the whole book is great but chapter 3 deals with methods common to all objects). Read more →