• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

mapping column of Date type

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In oracle database tbale "EVENT" I have some columns of "DATE" type. In the hibernate mapping file I specify as

<propery name="event_date" column="EVENT_COLUMN"/>

In the POJO "Event" class I have

private java.util.Date event_date;

Howevere I found it didn't work properly. Do I have to a

type="date"

in the hibernate mapping file ? like

<propery name="event_date" type="date" column="EVENT_COLUMN"/>

??
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here's an example:



Regards,
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know, annotations make things so much easier.



@Temporal(TemporalType.TIMESTAMP)
public java.util.Date getLastAccessTime() {
return lastAccessTime;
}

@Temporal(TemporalType.DATE)
public java.util.Calendar getRegistrationDate() {
return registrationDate;
}



Performing Date and Time Column Mappings with Hibernate and JPA Annotations


DATE vs. TIME vs. TIMESTAMP

It's noteworthy to point out how the registrationDate column, which is annotated to be TemporalType.DATE, simply gets a year-month-day value, whereas the lastAccessTime column is populated with a full timestamp, including both the day and the time (TemporalType.TIME is the third option which would have simply saved the time, and not the calendar day). By the way, TemporalType.TIMESTAMP is the default if it isn't otherwise specified in your code.



-Cameron McKenzie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic