This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using swing with Hibernate
Here are my code, and the problem is mentioned at the end of this post
My service class gets the date in required format, but , also converts it into String. Column in database is of 'Date' type. If i insert this String (i will have to change the datatype in my entity class as String), can i make operations related to Date in database and while generating reports? Is it a good approach or i should only insert it as a Date object?
Good thing will be inserting the date as Date Object, formatting can be done as & when it is getting displayed in UI. This way you have date operations without any complications of parsing it every time, also it will be helpful for managing of Time Zone if required (may be in future).
Joined: Jun 05, 2010
Thanks for your reply Anurag.
The user enters date in the textfield. I get it via getText() and parse it to Date object. But i need to validate the date entered before inserting it into db
Kunal Lakhani wrote:Column in database is of 'Date' type.
can i make operations related to Date in database and while generating reports?
As far as the database columns are date, all Db operations meant for reporting should work.
Am thinking from a simple SQL point of view.
If your inserts are successful, and date information is available in the DB for your records, SQL that creates reports should work.
Also, if you use hibernate for generating reports, criteria/HQL should be able to read it .. for them its a date column in the DB.
The fetcher would not know how you inserted.
But.. if your POJO( entity class ) has a string for the value.. you'll have to handle the hassles of converting date in DB -> String in hibernate -> date to generate reports
I think hibernate will handle the first half of above.
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"