File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes fake date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "fake date problem" Watch "fake date problem" New topic

fake date problem

andres buelo

Joined: Jan 31, 2010
Posts: 2
hi all,
I'm new to the world of struts 2 and hibernate, I'm working on a little project and I have to following problem. Hope someone can point me to the right direction.

I have a form with some date fields. The db doesn't accept null date but the form (only in some cases) does. I thought the only solution was to provide a "fake date" after submission like this:
1. the user submits form with one or more empty date fields
2. I change those date fields values to something like 9/9/9999 and store this value to the db.

on the other side, if I want to see data from the db>
1. I retrieve the data
2. I check the dates fields for value=9/9/9999 and change it to an empty string

I can only think at 3 solution right now: costumTypeConverter? a prepare() method? or just change the getter/setter on the Pojo ?
Actually I've tried the getter/setter solution, and it works for the view, but pull in some problem with Hibernate session/transaction referencing null values and making updates/insertion fail.

I think this could be a common problem, but with my zero knowledge I don't know if I'm working on the right direction. If this is the right direction I'll go on investigate on Hibernate exception. Do you have any suggestion ?

Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
andres buelo wrote: The db doesn't accept null date but the form (only in some cases) does.

Two possible solutions:

1. Make the DB accept null dates.
2. Make the form reject null dates.

David Newton

Joined: Sep 29, 2008
Posts: 12617

Beware the "magic date format". One place I worked at had no less than eight "magic dates". Impossible to maintain. We used Hibernate types. It was a nightmare. Turn back now.
andres buelo

Joined: Jan 31, 2010
Posts: 2
thanks for the reply

unfortunately I can't make the DB accept null dates, and my form rejects null dates only under some circumstances, in some cases I have the need to make the form accept it...

thanks for the suggestion, but what other solution can I adopt? I didn't understand if you are telling me to use Hibernate types or not..

I agree. Here's the link:
subject: fake date problem
It's not a secret anymore!