java.lang.ClassCastException: net.sf.hibernate.collection.Map

Hibernate JIRA | Will Glass-Husain | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    The code generator used a SortedMap to represent the following composite element. <class name="com.wgh.om.Rent" table="rent"> <meta attribute="generated-class">com.wgh.om.base.Rent</meta> <id name="rent_id" type="long" unsaved-value="null"> <generator class="identity"/> </id> <map name="amenities"> <key column="rent_id" /> <index column="name" type="string" /> <composite-element class="com.wgh.om.RentAmenity"> <meta attribute="generated-class">com.wgh.om.base.RentAmenity</meta> <property name="name" type="string" not-null="true"/> <property name="category" type="int" /> </composite-element> </map> </class> When I saved the class with this code, I received a PropertyAccessException from cglib. (with the optimizer turned off). hs = HibernateWrapper.getNewSession(ctx); o = new Rent(); o.setAmenities(new TreeMap()); hs.close(); hs = HibernateWrapper.getNewSession(ctx); hs.saveOrUpdate(o); hs.flush(); hs.connection().commit(); hs.close(); 2003-07-13 19:29:04 DEBUG java.lang.ClassCastException: net.sf.hibernate.collection.Map at com.novogradac.valuation.om.RentMetaClass3.setPropertyValues(<generated>) at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:158) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:724) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214) The solution was to either (A) add sort="natural" to the map hbm.xml, or to change the generated code to use Map instead of SortedMap. Recommendation-- have the codegenerator only use SortedMaps when the sorted attribute is present in the hbm.xml.

    Hibernate JIRA | 1 decade ago | Will Glass-Husain
    java.lang.ClassCastException: net.sf.hibernate.collection.Map
  2. 0

    The code generator used a SortedMap to represent the following composite element. <class name="com.wgh.om.Rent" table="rent"> <meta attribute="generated-class">com.wgh.om.base.Rent</meta> <id name="rent_id" type="long" unsaved-value="null"> <generator class="identity"/> </id> <map name="amenities"> <key column="rent_id" /> <index column="name" type="string" /> <composite-element class="com.wgh.om.RentAmenity"> <meta attribute="generated-class">com.wgh.om.base.RentAmenity</meta> <property name="name" type="string" not-null="true"/> <property name="category" type="int" /> </composite-element> </map> </class> When I saved the class with this code, I received a PropertyAccessException from cglib. (with the optimizer turned off). hs = HibernateWrapper.getNewSession(ctx); o = new Rent(); o.setAmenities(new TreeMap()); hs.close(); hs = HibernateWrapper.getNewSession(ctx); hs.saveOrUpdate(o); hs.flush(); hs.connection().commit(); hs.close(); 2003-07-13 19:29:04 DEBUG java.lang.ClassCastException: net.sf.hibernate.collection.Map at com.novogradac.valuation.om.RentMetaClass3.setPropertyValues(<generated>) at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:158) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:724) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214) The solution was to either (A) add sort="natural" to the map hbm.xml, or to change the generated code to use Map instead of SortedMap. Recommendation-- have the codegenerator only use SortedMaps when the sorted attribute is present in the hbm.xml.

    Hibernate JIRA | 1 decade ago | Will Glass-Husain
    java.lang.ClassCastException: net.sf.hibernate.collection.Map

    Root Cause Analysis

    1. java.lang.ClassCastException

      net.sf.hibernate.collection.Map

      at com.novogradac.valuation.om.RentMetaClass3.setPropertyValues()
    2. com.novogradac.valuation
      RentMetaClass3.setPropertyValues
      1. com.novogradac.valuation.om.RentMetaClass3.setPropertyValues(<generated>)
      1 frame
    3. net.sf.hibernate
      SessionImpl.saveOrUpdate
      1. net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:158)
      2. net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:724)
      3. net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
      4. net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1214)
      4 frames