Java: JPA classes, refactoring from Date to DateTime
Posted
by bguiz
on Stack Overflow
See other posts from Stack Overflow
or by bguiz
Published on 2010-05-26T14:14:54Z
Indexed on
2010/05/26
14:21 UTC
Read the original article
Hit count: 278
With a table created using this SQL
Create Table X (
ID varchar(4) Not Null,
XDATE date
);
and an entity class defined like so
@Entity
@Table(name = "X")
public class X implements Serializable {
@Id
@Basic(optional = false)
@Column(name = "ID", nullable = false, length = 4)
private String id;
@Column(name = "XDATE")
@Temporal(TemporalType.DATE)
private Date xDate; //java.util.Date
...
}
With the above, I can use JPA to achieve object relational mapping. However, the xDate
attribute can only store dates, e.g. dd/MM/yyyy
.
How do I refactor the above to store a full date object using just one field, i.e. dd/MM/yyyy HH24:mm
?
© Stack Overflow or respective owner