王奕然
王奕然

Reputation: 4049

hibernate TemporalType ,datetime column mapping

i have column type is datetime in mysql

and i use hibernate @Temporal(TemporalType.TIMESTAMP) private java.sql.Timestamp lastExpressTime;

@Temporal(TemporalType.TIMESTAMP)
private java.util.Date lastExpressTime;

@Temporal(TemporalType.DATE)
private java.sql.Date lastExpressTime;

are there some difference between those?

datetime should mapping what kind of TemporalType?

i find a reference Table 5.2 MySQL Types to Java Types for ResultSet.getObject() datetime should mapping timestamp?

thanks for your any help and suggestion in advance

Upvotes: 0

Views: 1238

Answers (1)

Predrag Maric
Predrag Maric

Reputation: 24423

With TemporalType.TIMESTAMP, when you persist/read lastExpressTime to/from database, both date and time will be persisted/read.

With TemporalType.DATE, when you persist/read lastExpressTime to/from database, only date will be persisted/read and time part of the date will be set to all zeroes.

Not sure if this behavior is the same for all databases, best would be to check this in your own test.

Upvotes: 2

Related Questions