In one of my Grails consulting projects we tried to define database indices via the static mapping element in the domain classes. A team member tried it an told me that this does not work so I digged a bit deeper to find out what the problem was.
I created a simple test project, configured hbm2ddl
auto to update, like I am used to and let Grails create a MySQL database schema. It seemed lie my colleague was right, the defined indices were not created (using Grails 1.3.7). Doing some web research brought up this Stackoverflow posting suggesting that indices are only created when hbm2ddl
auto was set to create (or create-drop) - which seemed to be the case.
Read more →
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
. This is how the nested session structure looks like while the job is running:
Read more →
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. Why did Hibernate want to do this? Another interesting thing was that Hibernate was able to create tables for the same model on other developer machines before.
Read more →
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. It is configured for error
per default which does not show if something is wrong in your XML configuration files.
Read more →
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 →
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. As I am a Java developer and I am using Grails in many of our latest projects groovy is a known environment for me.
Read more →
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. When starting the app it created all the tables in my database with in lowercase and with underscores instead of camel case naming.
Read more →
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. I was quite enthusiastic but my anticipations were not quite met. The current version only includes the OS6 library but our product timr needs to be released for OS5. The second drawback was that they just ported the rapc compiler but not the fledge simulator. The marketing statement on the BlackBerry site is:
Read more →
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.country=c.id group by c.code order by co desc
I had to add the “as co” alias to the count column to use it in the order command at the end of the SQL. How could this be done in a GORM criteria? The basic criteria with the result of the first SQL looked like:
Read more →
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 →