I have an object which contains prices. The table column type for these properties is ‘Float’. The columns are nullable.
One of these properties is “priceNonMember”.
When I run the following:
orm.populate(orm.new("Event"),arguments);
Where priceNonMember is included in arguments, but is empty, I receive the following error:
Error Type: Application : [N/A] Error Messages: Property : priceNonMember - The value ‘’ cannot be converted to a number.
Root cause :org.hibernate.HibernateException: Property : priceNonMember - The value ‘’ cannot be converted to a number.
Is it possible for Orm Services to handle Nullable float properties?
Does arguments contain a key for “priceNonMember”? If so, you might add the ignoreEmpty=true argument to your call to populate(). This will prevent that key from being processed when the populate runs. Alternatively, you can simply exclude that property from the argument collection, and it should accomplish the same thing.
I, personally, haven’t found one on the populate methods and javacast() will set empty interferes and floats to 0.
What I have done is run my structure (eg - the request collection) through a method that removes the nulls numerics/floats/empty bits from the structure passed.
For example:
event = populateModel(“event”, filterProperties(event.getCollection()));
@Jason-- Awesome, glad it worked. @Andrew – In this scenario, a default value on the DB doesn’t matter since the error was occurring in the populate().
Can’t speak for Jason’s business requirements, but I would imagine it’s because it’s a “price” related field. Big difference between a NULL and a price of 0.00!
Hi Joel, the price field is an optional value in a form.
From the clients perspective $0 indicates it is worth $0 (free), which is different to ‘no price’. This makes sense to me as well. $0 is different to ‘no price’.
If I set ignoreEmpty=true, there is now no way for the user to clear a field in the form that is populating the model via the populate method with ignoreEmpty=true. For example, there is a field in the form that is passed in to populate the model called “venue”. If the user decides to empty this, and clears the text from the field, then submits the form, it doesn’t clear the text because the populate method is now ignoring that empty field.
Can anyone suggest a way around this? The only thing I can think of is to set the default value to ‘0’ for the float values after all… then having to handle this in my views…