• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having Diffyerent data types in the DB and DTO in Hibernate

 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

in my database, i m storing a date property as a Date object and in my DTO i m storing the property as an instance field of type Date. but in my getDate method i m returning a long ( date.getTime()). and i keep getting a classCastException when testing this code.
Is it possible to have the type in the getters and setters different than the type of the instance fields, or to have the date in the DB as a Date, then in the mapping having it as a long?

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

Why do you need to do this? A Date object has a method on it to get a long value, any reason you don't just use this?
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:No.

Why do you need to do this? A Date object has a method on it to get a long value, any reason you don't just use this?


if it is up to me i would just keep everything as date and just use the GetTime when i need a long, but the project description says that the date in the DB should be Date and in the DTO should be long.

Thanks for your response
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic