ITeye博客

hibernate 无主键表的处理

luowei31 · 2011-11-17 10:12 · java · hibernate · 编程语言 · Markdown

1、hibernate 无主键表的处理可看成多主键表来处理

2、多主键entity对象定义方式需要实现Serializable接口

并且重写equals(Object obj)和hashCode()两个方法,下面是例子

 

public boolean equals(Object obj) {

        if(obj == this) {
            return true;
        }

       

        if(!(obj instanceof Login)) {
            return false;
        }

        Login login = (Login) obj;

        return new EqualsBuilder()
                 .append(this.branch_no, login.getBranch_no())
                 .append(this.card_enter, login.getCard_enter())
                 .append(this.teller_no, login.getTeller_no())
                 .append(this.time, login.getTime())
                 .append(this.frequency, login.getFrequency())
                 .isEquals();
    }

public int hashCode() {
        return new HashCodeBuilder()
		        .append(this.branch_no)
		        .append(this.card_enter)
		        .append(this.teller_no)
		        .append(this.time)
		        .append(this.frequency)
                .toHashCode();
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。