---
title: "hibernate 无主键表的处理"
author: "luowei31"
date: "2011-11-17T10:12:06Z"
tags: []
categories: ["编程语言"]
slug: "hibernate"
draft: false
lastmod: "2011-11-17T10:12:06Z"
id: 1263424
url: "https://luowei31.iteye.com/blog/1263424"
---

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();
    }
```