티스토리 뷰
The annotation @Temporal in official javadoc is described like below:
This annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar.
So when the field variable is a java.util.Date or java.util.Calendar, it MUST be annotated by @Temporal.
There are 3 values for @Temporal
- TemporalType.DATE
- TemporalType.TIME
- TemporalType.TIMESTAMP
Here is a demo to show the usage of there 3 values. The Entity 'MyEntity' has a field called 'lastUpdateTime' which is a defined as a java.util.Date variable. let's update it in java like this:
import java.util.Date;
//...
// MyEntity is the JPA entity, em is EntityManager context
MyEntity e = em.find(MyEntity.class, 1L); //get the row with id=1
e.setLastUpdateTime(new Date());
TemporalType.DATE
If the column annotated with @Temporal(TemporalType.DATE) like this:
@Temporal(TemporalType.DATE)
@Column(name="LAST_UPDATE_TIME")
private Date lastUpdateTime;
The record in database after update will look like:
TemporalType.TIME
If the column annotatedwith @Temporal(TemporalType.TIME) like this:
@Temporal(TemporalType.TIME)
@Column(name="LAST_UPDATE_TIME")
private Date lastUpdateTime;
The record in database after update will look like:
TemporalType.TIMESTAMP
If the column annotated with @Temporal(TemporalType.TIMESTAMP) like this:
@Temporal(TemporalType.TIMESTAMP)
@Column(name="LAST_UPDATE_TIME")
private Date lastUpdateTime;
The record in database after update will look like:
출처 : http://shengwangi.blogspot.kr/2014/12/the-value-of-annotation-temporal-for-date-column.html
'Study > JPA' 카테고리의 다른 글
JPA 관계 설정 (0) | 2019.04.10 |
---|---|
JPA 요약 PPT (0) | 2019.04.10 |
jpa entity 상속 (0) | 2019.04.10 |
@OneToMany , @ManyToOne fetch 관련 (0) | 2019.04.10 |
entityManager 와 entityManagerFactory (0) | 2019.04.10 |
- Total
- Today
- Yesterday
- coroutine
- java 설치
- jstl foreach
- java 압축 풀기
- java calendar
- Kotlin
- jstl 커스텀 태그
- Database#transaction
- spring property
- POE Excel 만들기
- spring ExcelView
- mybatis Merge
- java 폴더구조 구하기
- java 설정
- MyBatis 팁
- POI EXCEL
- 코루틴
- java 특정문자 갯수구하기
- JSP 세션
- github image 첨부시 주의할점
- JSTL
- jstl split
- 전자정부프레임워크 tiles
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |