Hello everybody,
I am getting some ClassCast exception (java.lang.ClassCastException: org.hibernate.proxy.MapProxy) while trying to load from DB a class that implements the Map interface. Is there any known "clue" about playing with Maps ?
Many thanks for your help, suggestions...
Here are some details about this pb
First I use the EntityMode.MAP on my session:
Code:
Session sess = sessionFactory.openSession();
Session dynSession = sess.getSession(EntityMode.MAP);
I am trying to save/load a class that implements the Map interface:
Quote:
public class AddressMapImpl implements Address,Serializable, Map {
private HashMap internalMap;
public AddressMapImpl() {
internalMap = new HashMap();
internalMap.put("id",null);
internalMap.put("zipCode",null);
internalMap.put("country",null);
internalMap.put("street",null);
}
public String getId() {...}
public void setId(String id) {...}
...
}
And the hbm file is as follow:
Code:
<hibernate-mapping>
<class entity-name="com.mb.simpledemo.model.user.Address" table="ADDRESS">
<id name="id" type="string" column="ADDRESS_ID">
<generator class="uuid.hex"/>
</id>
<property name="zipCode" type="string">
<column name="ZIPCODE" unique="false"/>
</property>
<property name="country" type="string">
<column name="COUNTRY" unique="false"/>
</property>
<property name="street" type="string">
<column name="STREET" unique="false"/>
</property>
...
I am able to persist instances of this class using the following code:
Code:
Session dynSession = sess.getSession(EntityMode.MAP);
Transaction tx=dynSession.beginTransaction();
dynSession.saveOrUpdate("com.mb.simpledemo.model.user.Address",this);
tx.commit();
sess.close();
But if i try to load a class using the following code:
Code:
String id=...
Session dynSession = sess.getSession(EntityMode.MAP);
Address obj = (Address) dynSession.load("com.mb.simpledemo.model.user.Address", id);
i get a ClassCast exception:
java.lang.ClassCastException: org.hibernate.proxy.MapProxy
Any thought, suggestion, magic idea ?
Thanks a lot for your help,
Best Regards