is @Temporal preferred to @Column columnDefinition?
Which is best practice?
@Column(name = "FOO", columnDefinition = "TIMESTAMP")
private Date foo;
Or
@Column(name = "FOO开发者_JAVA百科")
@Temporal(TemporalType.TIMESTAMP)
private Date foo;
The documentation suggests that using columnDefinition is non-portable ...
The documentation suggests that using columnDefinition is non-portable ...
That's true. columnDefinition
specified the SQL data type that will be used. This data type may however not be available in all RDBMS. In JPA, it's the JPA provider's duty to figure out what SQL works on what DB. You can specifiy part of that configuration, but you will always risk breaking support for some databases.
@Temporal
on the other hand is an abstraction that is part of the JPA standard. Every JPA provider must be able to map the different types of @Temporal
to different SQL types for all supported databases.
精彩评论