parent.java

来自「hibernate3.2.6源码和jar包」· Java 代码 · 共 51 行

JAVA
51
字号
//$Id: Parent.java 11282 2007-03-14 22:05:59Z epbernard $package org.hibernate.test.annotations.onetomany;import java.io.Serializable;import java.util.HashSet;import java.util.Set;import javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.Id;import javax.persistence.OneToMany;import org.hibernate.annotations.BatchSize;/** * @author Emmanuel Bernard */@Entitypublic class Parent implements Serializable {	@Id	public ParentPk id;	public int age;	@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")	@BatchSize(size = 5)	@javax.persistence.OrderBy("favoriteSuperhero asc, favoriteSinger desc")	public Set<Child> children;	public int hashCode() {		//a NPE can occurs, but I don't expect hashcode to be used before pk is set		return id.hashCode();	}	public boolean equals(Object obj) {		//a NPE can occurs, but I don't expect equals to be used before pk is set		if ( obj != null && obj instanceof Parent ) {			return id.equals( ( (Parent) obj ).id );		}		else {			return false;		}	}	public void addChild(Child child) {		if ( children == null ) {			children = new HashSet();		}		child.parent = this;		children.add( child );	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?