I'm trying to persist an Entity containing a HashMap. It stores the data in the database OK, but the map is always empty when I get the entity out of the database again.
I've reproduced this problem in a simple variation of the Guestbook tutorial:
Guest class:
=====================
@Entity public class Guest implements Serializable { private static final long serialVersionUID = 1L; // Persistent Fields: @Id @GeneratedValue Long id; private String name; private Date signingDate; private HashMap<String, String> map = new HashMap<String, String>(); // Constructors: public Guest() { } public Guest(String name) { this.name = name; this.signingDate = new Date(System.currentTimeMillis()); map.put(name, signingDate.toString()); } // String Representation: @Override public String toString() { return name + " : signed on " + signingDate + "; from map : " + map.get(name); }
==========================
GuestDao is the same as the tutorial
Test class:
==========================
public class GuestTest { private GuestDao guestDao; @Test public void test() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-servlet.xml" }); guestDao = context.getBean(GuestDao.class); Guest tst = new Guest("testname"); guestDao.persist(tst); List<Guest> result= guestDao.getAllGuests(); System.out.println(result.get(0).toString()); } }
================
Please advise what I need to do to get the map.
The full Eclipse project attached FYI.
Thanks,
Natalia.