-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: org.hibernate.util.IdentityMap doesn't implement Map fully?
PostPosted: Thu Mar 02, 2006 6:34 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
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]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 9:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate only uses this class internally. It does not use this for the maps it returns for <map/> mappings.

You are trying to marshall the Session!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:08 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
steve wrote:
Hibernate only uses this class internally. It does not use this for the maps it returns for <map/> mappings.

You are trying to marshall the Session!


Thanks for your quick response.


hmmm. To confirm what i think might be causing this based on your answer.

Hibernate returns a Party object to me that i've loaded from the database. Does this mean that this Party object (or the proxy for it) has public methods that expose the internals of Hibernate (like session, as you suggest)?

Because we do ask castor to auto serialize (it looks for public get/set).

If so, yeah, i can see that happening. No way around it? Am i going to have to go through all my Castor mappings and explicitly call out the methods and attributes i want to serialize?

thanks again for your reply.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:41 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
Thanks Steve, for pointing out the problem.

I confirmed it's the method getHibernateLazyInitializer, that is causing the damage. Not sure how to fix this. I can't tell Castor to bypass this method as it doesn't exist in the Class i'm telling Castor to serialize ...

bummer.

I'll think of something.

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 8:29 pm 
Newbie

Joined: Wed Sep 27, 2006 8:24 pm
Posts: 1
Hi,

I have the same problem, did you ever solve it?
Any help will be appreciated.

Hibernate 3.1.3
Castor 1.0.1

Thks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 9:29 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
javaigua wrote:
Hi,

I have the same problem, did you ever solve it?
Any help will be appreciated.

Hibernate 3.1.3
Castor 1.0.1

Thks


The problem actually lies in Castor. If you are using

auto-complete="true" on objects in Castor, it will use reflection on the object. The problem is that the object you are marshalling through Castor is now proxied, and it has other methods that Castor will pick up and try to marshall (like getSession()). You cannot exclude them in your Castor mapping file, because you cannot exclude methods that do not exist.

Fortunately the Castor developers were made aware of it. It has been awhile, but it looks like they developed a fix for this issue:

http://jira.codehaus.org/browse/CASTOR- ... tion_73415


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.