我尝试在此类中使用 Hibernate,其中包括
ArrayList
:
但我得到了这个例外:
expected type: java.util.ArrayList, actual value: org.hibernate.collection.PersistentList
(我必须使用 Arraylist,因为 List 是不可序列化的,这给我带来了麻烦)
当 jpa entitymanager 启动时抛出此异常。
这是课程:
package Entities;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import msg.AnsMsg;
public class Person implements Serializable {
static final long serialVersionUID = 1L;
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
private String _email;
private ArrayList <AnsMsg> msgList=new ArrayList<AnsMsg>();
public ArrayList <AnsMsg> getMsgList() {
return msgList;
}
public void setMsgList(ArrayList <AnsMsg> msgList) {
this.msgList = msgList;
}
public Person(){}
public String getEmail() {
return _email;
}
public void set_email(String _email) {
this._email = _email;
}
}
这是hbm文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 17, 2012 9:20:13 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Entities.Person" table="PERSON">
<id name="id" type="long">
<column name="ID" />
<generator class="increment" />
</id>
<property name="_email" type="java.lang.String" access="field">
<column name="_EMAIL" />
</property>
<list name="msgList" inverse="false" table="ANSMSG" lazy="true">
<key>
<column name="ID" />
</key>
<list-index></list-index>
<one-to-many class="msg.AnsMsg" />
</list>
</class>
</hibernate-mapping>
我如何在休眠中使用java Arraylist,在此先感谢。