key words:hibernate,load,session.get,session.load()
public class Parent implements Serializable {
/** identifier field */
private Long id;
/** persistent field */
private List childs;
/** full constructor */
public Parent(Long id, List childs) {
this.id = id;
this.childs = childs;
}
/** default constructor */
public Parent() {
}
/**
* @hibernate.id
* generator-class="assigned"
* type="java.lang.Long"
* column="id"
*
*/
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
/**
* @hibernate.set
* lazy="true"
* inverse="true"
* cascade="none"
* @hibernate.collection-key
* column="parent_id"
* @hibernate.collection-one-to-many
* class="net.foxlog.model.Child"
*
*/
public List getChilds() {
return this.childs;
}
public void setChilds(List childs) {
this.childs = childs;
}
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof Parent) ) return false;
Parent castOther = (Parent) other;
return new EqualsBuilder()
.append(this.getId(), castOther.getId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getId())
.toHashCode();
}
}
Parent parent = (Parent)session.load(Parent.class,new Integer(7));
运行提示出错,"can't get Entity.."
知道是什么低级错误么? 其实很弱智的东西,但是不注意还就会出现,呵呵,答案如下:
Parent parent = (Parent)session.load(Parent.class,new Long(7))