Posted by: nerdgerl on: June 18, 2009
I recently came across this problem when I added Hibernate to a project. If you have an entity like:
@Entity
@Table(name = "upload")
public class Upload {
@Id
@Column(name = "upload_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer uploadId;
@Column(name = "user_id")
private String userId;
@Transient
private Integer rowsExported;
@Column(name = "adjustment_type")
@Enumerated(EnumType.STRING)
private ManualAdjustmentType adjustmentType;
@Column(name = "upload_time_stamp")
private DateTime uploadTimeStamp;
@Column(name = "status")
@Enumerated(EnumType.STRING)
private UploadStatus status;
}
@Column(name = "cut_off_date") <strong>@Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDate")</strong> private LocalDate cutOffDate; @Column(name = "upload_time_stamp") <strong>@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")</strong> private DateTime uploadTimeStamp;</pre>
If you are unlucky enough to be dealing with dates stored as Strings in the database, take a look at this post.
1 | Joda with JPA « Objectopia
July 16, 2009 at 7:05 am
[...] Posted by Chris Clark on July 10, 2009 I have to work with a few legacy databases that are used by several different apps (apparently the database is a perfect integration point), and I want to use the Joda api in my persistence. In this example the date is actually stored as a string, genius! I’m going to use LocalDate as the string doesn’t store the time element. If you are lucky enough and the database is actually storing date time check this post out Joda With DateTime [...]