티스토리 뷰
http://stackoverflow.com/questions/3585034/how-to-map-a-composite-key-with-hibernate
@ID 방식과 @Embeddable 방식이 있는데 후자의 방식으로 코딩했다.(이유는 @Id 방식으로 했을 때 에러가 나서?)
TagBusy의 PK 정보를 TagBusyId가 가지고 있다(3가지 복합키)
@Entity
@Table(name = "tag_busy")
public class TagBusy {
@EmbeddedId
private TagBusyId tagBusyId; //PK
@Column(name = "reg_date", nullable = true, insertable = false, updatable = false)
private Date regDate; //등록일시
public TagBusyId getTagBusyId() {
return tagBusyId;
}
public void setTagBusyId(TagBusyId tagBusyId) {
this.tagBusyId = tagBusyId;
}
public Date getRegDate() {
return regDate;
}
public void setRegDate(Date regDate) {
this.regDate = regDate;
}
}
@Embeddable
public class TagBusyId implements Serializable {
@ManyToOne(optional = false)
@JoinColumn(name = "tag_no", nullable = false)
private Tag tag; //태그
@Column(name = "cnts_no", nullable = false)
private int cntsNo; //컨텐츠번호
@Column(name = "cnts_type", nullable = false)
private int cntsType; //컨텐츠타입
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TagBusyId tagBusyId = (TagBusyId) o;
if (cntsNo != tagBusyId.cntsNo) return false;
if (cntsType != tagBusyId.cntsType) return false;
if (tag != null ? !tag.equals(tagBusyId.tag) : tagBusyId.tag != null) return false;
return true;
}
@Override
public int hashCode() {
int result = tag != null ? tag.hashCode() : 0;
result = 31 * result + cntsNo;
result = 31 * result + cntsType;
return result;
}
public Tag getTag() {
return tag;
}
public void setTag(Tag tag) {
this.tag = tag;
}
public int getCntsNo() {
return cntsNo;
}
public void setCntsNo(int cntsNo) {
this.cntsNo = cntsNo;
}
public int getCntsType() {
return cntsType;
}
public void setCntsType(int cntsType) {
this.cntsType = cntsType;
}
}
'공부 > ORM, JPA, Hibernate' 카테고리의 다른 글
hibernate openSessionInViewFilter (0) | 2015.05.11 |
---|---|
[When use getOne and findOne methods Spring Data JPA (0) | 2015.04.30 |
Change from Hibernate to JPA & Apply SpringData JPA, QueryDsl, hsqldb (0) | 2015.04.28 |
[hibernate] test rollback 문제 (0) | 2015.04.27 |
[hibernate] 자동으로 스키마 생성 (0) | 2015.04.27 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 메모장
- 이론
- db
- 정보
- 도전과제
- jsp
- 잡담
- JQuery
- 청주
- 아두이노
- 데이터베이스
- SQL
- CSS
- 파이썬
- 프로젝트
- 알고리즘
- 충북대
- 소켓
- 오라클
- HTML
- 자바
- SVN
- 안드로이드
- 졸업작품
- ERP
- 정렬
- 배열
- 클래스
- 게임
- 자바스크립트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함