skaz
skaz

Reputation: 22640

Data Validation with ORM

I have a Grails application that is dependent upon an external dataset that gets sucked in periodically. There is no way to validate the data when it comes into the database, because the program that sucks it in isn't written by us.

Once in a while, we get a bad piece of data in the database. For example, a number is "5,5" instead of "5.5". The datatype on the column (since they defined the table) is VARCHAR even though the field should always contain a number. Our application has this column mapped to a FLOAT in the ORM layer, since that is what we expect it to be.

I want to make sure that the application doesn't crash when we get new data, but I am not sure how. Should I map the column to a VARCHAR and then do a conversion to a transient FLOAT column or something like that?

Upvotes: 2

Views: 121

Answers (1)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

Short-term, yes, mapping the VARCHAR to String in the domain object instead of a numeric type would solve the problem.

In my opinion, a better solution would be to do the periodic import into a different table, and have a process that moves only valid rows to the domain table. You'd probably also want to put the 'bad' rows somewhere, and notify someone to manually fix them.

Upvotes: 2

Related Questions