Grails Legacy Database Tips and Tricks

0
April 3, 2014 at 8:10 pm  •  Posted in Grails by  •  0 Comments

Grails Legacy Database Tips and Tricks

Sometimes a legacy database is a necessary evil and requires extra configuration in Grails to get around previous schema choices. Luckily, Grails provides configuration options to make life in the past a little easier. As I learn more about working with Grails and legacy databases, I will update this post and hopefully let others learn from my experience.

Grails Legacy Database Tip #1 – Don’t Convert Empty Strings to Null

By default, Grails converts empty strings to null values. What is an empty string? It is a string with no characters or only whitespace. {adinserter 1}I have worked with legacy databases which do not allow null values but have fields which are optional for each record. The design choice during creation was to not allow null values but instead, insert whitespace as a replacement for null. Unfortunately, changing the table to allow nulls happened to be out of the question.

Grails configuration to the rescue!

This simple line can be placed in Config.groovy to disable the conversion of empty strings to null!

Grails Legacy Database Tip #2 – Stop Trimming Strings!

While working with a 10 year old ERP system, I found that the system actually used spaces before and after a string to determine if the data should be left or right aligned in the program. Grails trims white space around database values by default but can be turned off easily.

Again, add this to Config.groovy and save yourself a headache!

Do you have any Grails Legacy Database tips that you would like to share?

 

 

Tags:

Leave a Reply