Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

연관성이 있는 두 테이블이 유니크한 복합키로 지정이 되어 있으며동일한 유니크 조건을 가지고 있으나

다른 복합키 설정이되어있으며 관계도를 형성하는 외래키설정을 무시했을때관계도를 형성하는 외래키 설정이 없을때


두가지 상황으로 볼수 있습니다.

  • 설계상의 문제 : 무결성을 지킬필요가 있어 외래키가 설정이 요구되나, 무시한경우
  • 의도된 상황 : 무결성을 지킬필요없는 로그성및 통계성


관련 영문 키워드 :

mapping compositekey primary and non forign

...

Code Block
languagejava
themeEmacs
import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class ItemId implements Serializable {
	
	@Column(columnDefinition="char(71)")  //특수데이터 데이터 Type 변환방법 char(1) -> string
	private String	itemtype;
	private int		itemno;
	
    public ItemId() {

    }
	
    public ItemId(String itemtype, int itemno) {
        this.itemtype = itemtype;
        this.itemno = itemno;
    }
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = itemtype.hashCode() + itemno;
		return result;
	}
 
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemId other = (ItemId) obj;
		if (itemtype == null) {
			if (other.itemtype != null)
				return false;
		} else if (!itemtype.equals(other.itemtype))
			return false;
		if (itemno != other.itemno)
			return false;
		return true;
	}
	
	public String getItemtype() {
		return itemtype;
	}
	public void setItemtype(String itemtype) {
		this.itemtype = itemtype;
	}
	public int getItemno() {
		return itemno;
	}
	public void setItemno(int itemno) {
		this.itemno = itemno;
	}

}

...