• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

fake date problem

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

 
Author
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
 
rubbery bacon. rubbery tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic