Message:
The following issue has been re-assigned.
Assignee: Max Rydahl Andersen (mailto:xa...@xa...)
Assigner: Gavin King (mailto:ga...@in...)
Date: Sun, 13 Jul 2003 9:34 PM
Comment:
Isn't this fixed already? I thought it was ....
What version are you using?
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-190
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-190
Summary: codegenerator creates SortedMap when it should create Map
Type: Bug
Status: Assigned
Priority: Major
Project: Hibernate2
Components:
toolset
Versions:
2.0 final
Assignee: Max Rydahl Andersen
Reporter: Will Glass-Husain
Created: Sun, 13 Jul 2003 9:30 PM
Updated: Sun, 13 Jul 2003 9:34 PM
Environment: Win XP/JDK 1.3.1
Description:
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.
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|