Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fake date problem

 
andres buelo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

thanks
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply

@Lorand
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...

@David
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..

Andres
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic