-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Persisting a List of objects containing a HashMap
PostPosted: Thu Jan 28, 2010 5:53 am 
Newbie

Joined: Wed Jan 27, 2010 11:36 am
Posts: 1
Hi there,

I'm pretty new to Hibernate and completely stuck. I want to persist the following in MySQL5:

Code:
package mypackage;
public class Job implements Serializable {
...
private static final long serialVersionUID = ...
private long id;
private List<Task> tasks = new ArrayList<Task>();
...
(getters/setters)
...
}


Code:
package mypackage;
public class Task implements Serializable {
...
private static final long serialVersionUID = ...
private long id;
private String taskName;
private Map<String, String> properties = new HashMap<String, String>();
...
(getters/setters)
...
}


The mappings so far:

Code:
...
<hibernate-mapping>
   <class name="mypackage.Job"
      table="transcoder_jobs">
      <id name="id" column="id" type="long" length="11">
         <generator class="increment" />
      </id>
...
<list name="tasks" table="job_tasks">
         <key column="id" />
         <list-index column="sequence" />
         <element type="mypackage.Task" column="task" not-null="true"/>
      </list>
</class>
</hibernate-mapping>


Code:
<hibernate-mapping>
   <class name="mypackage.Task"
      table="job_tasks">
      <id name="id" column="id" type="long" length="11">
         <generator class="native" />
      </id>
      <property name="taskName" type="string">
         <column name="taskName" not-null="false" />
      </property>
   <property name="properties" type="java.util.HashMap" update="false">
      <column name="properties" not-null="true" />
   </property>
   </class>
</hibernate-mapping>


Basically, it's one object containing a List of other objects which are holding a string/string Map.

The code works so far, i can save objects, but the properties-map (which is a BLOB in the DB) is 0 bytes in size.
But when i try to retrieve an object, I get a

Code:
org.hibernate.type.SerializationException: could not deserialize


What's wrong here? I guess I have to set some kind of relation between objects in the mappings, but I have no idea which one and how.
Or am I completely wrong here?

Any help is _VERY_ highly appreciated, a working example of such a mapping would be just perfect!

Thank you very much for your help!
-- snowcrashed


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.