I have no problems persisting and reading the Class below that contains a Map of addresses.
The problem i'm having is that when I load it from the database and then pass it to our XML Serializer (Castor), I get an exception when Castor expects to be able to issue a
Code:
Set keySet();
It appears that Hibernate which slips it's own IdentityMap in place of java's Map, does not support this:
Code:
public Set keySet() {
// would need an IdentitySet for this!
throw new UnsupportedOperationException();
}
It is not clear to me how to get around this. Have i mismapped it? It's defined as a plain old java.util.map. I had thought that perhaps i needed to insure that the map was loaded, but i accessed it and loaded it before passing it to XMLSerializer.
I'm stuck, is there any way around this? I'll need to take my loaded object and serialize it into XML and pass it to our client. In fact, that code has been running for awhile.
Please, any pointers would be worthwhile!
Details below
Hibernate version:3.1 Mapping documents: A subset
Code:
<hibernate-mapping>
<class name="com.trivin.bo.party.Party" table="PARTY">
<id name="partyID" column="PARTYID" type="long">
<generator class="native"/>
</id>
<discriminator column="DSCR" type="string"/>
<property name="productID" type="integer" column="PRODUCTID"/>
<!-- Mapped collection of Addresses keyed by Address Role -->
<map name="addressMap" table="PARTY_ADDRESS" lazy="true" cascade="save-update">
<key column="PARTYID"/>
<index column="ADDRESS_ROLE" type="integer"/>
<many-to-many column="ADDRESSID" class="com.trivin.bo.party.Address"/>
</map>
</class>
<!-- Address Class -->
<class name="com.trivin.bo.party.Address" table="ADDRESS">
<id name="addressID" column="ADDRESSID" type="long">
<generator class="native"/>
</id>
<property name="productID" column="PRODUCTID" type="integer"/>
<property name="street1" column="STREET1" length="45"/>
<property name="street2" column="STREET2" length="45"/>
<property name="street3" column="STREET3" length="45"/>
<property name="city" column="CITY" length="35"/>
<property name="state" column="STATE" length="2"/>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
java.lang.UnsupportedOperationException
at org.hibernate.util.IdentityMap.keySet(IdentityMap.java:163)
at org.exolab.castor.mapping.handlers.J2MapHandler.keys(J2MapHandler.java:136)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1499)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1520)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1520)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1520)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:785)
at com.trivin.msg.xml.ERTMarshall.marshal(ERTMarshall.java:201)
at com.trivin.msg.xml.ERTMarshall.marshal(ERTMarshall.java:187)
at com.trivin.test.bo.TestMarshallObjects.marshall(TestMarshallObjects.java:168)
at com.trivin.test.persist.aa.userTests.TestIndividual.testInsert(TestIndividual.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
[/code]