Absence of @Temporal annotation in hibernate

前端 未结 2 1344
小鲜肉
小鲜肉 2021-02-05 03:40

What if we use

@Column(name=\"birth_date\", nullable=false, length=19)
public Date getBirthDate() {
    return this.birthDate;
}

instead of

2条回答
  •  抹茶落季
    2021-02-05 04:20

    I realize this question was already answered but we struggled with this today so I wanted to give some more insight for future people who stumble across this.

    Using Oracle 11g with the version 11 drivers if you do not use the temporal annotation then every date, time, and timestamp data type from Oracle will map to a timestamp in your code at runtime. Functionally this is fine, however this caused us severe performance issues. This was because we had a DATE type as part of a compound primary key. This column was the leading column of the index as well as the column we used for partitioning. When the driver would try to persist records with this column in the where clause Oracle would perform a type conversion of the data in the DB from DATE to TIMESTAMP. This made the index useless and performance was horrible.

    Long story longer, add this annotation always lest ye be prepared to pay the price.

提交回复
热议问题