i'm try to persist object (PERSON) with ArrayList but i get this execption:
ERROR:2012-04-23 20:58:54,336 org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: Entities.Person, setter method of property: msgList
ERROR:2012-04-23 20:58:54,336 org.hibernate.property.BasicPropertyAccessor - expected type: java.util.ArrayList, actual value: org.hibernate.collection.PersistentList
Person class:
public class Person implements Serializable {
static final long serialVersionUID = 1L;
private long id;
private String _email;
private ArrayList<AnsMsg> msgList=new ArrayList<AnsMsg>();
long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return _email;
}
public void set_email(String _email) {
this._email = _email;
}
public ArrayList<AnsMsg> getMsgList() {
return msgList;
}
public void setMsgList(ArrayList<AnsMsg> msgList) {
this.msgList = msgList;
}
}
Person Hbm:
<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" cascade="all" >
<key column="parent_id"/>
<index column="idx" />
<one-to-many class="msg.AnsMsg" />
</list>
</class>
</hibernate-mapping>
now i don't want to use List instead ArrayList
(private List<AnsMsg> msgList=new ArrayList<AnsMsg>();)
because when i get person from DB Hibernate return org.hibernate.collection.PersistentList and i need to Serialize and Deserialize this object (Java server and android app) and "org.hibernate.collection.PersistentList" is't implements Serializable (or i'm wrong because i get null object when i try to Deserialize in android side).
this is my Deserialize/Serialize method:
public static byte[] serializeObject(Object o) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
out.close();
byte[] buf = bos.toByteArray();
return buf;
}
catch(IOException ioe)
{
return null;
}
catch(Exception e)
{
return null;
}
}
public static Object deserializeObject(byte[] b) {
Object object=null;
try {
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
object = in.readObject();
in.close();
return object;
} catch(ClassNotFoundException cnfe) {
return null;
} catch(IOException ioe) {
return null;
}
catch(Exception e)
{
String ex=e.toString();
return object;
}
}
Update:
when i try to use List instead ArrayList
when i try do Deserialize this object in the android side (with "deserializeObject" method ) when i get to
object = in.readObject();
line it's throw
java.lang.ClassNotFoundException: org.hibernate.collection.PersistentList.
this way i try to use ArrayList.
how can i map this array list? or there is a batter way to work with Hibernate in this case?
thanks in advance..