For reasons I won't get into here, we need to pack a bunch of information into an XMLTYPE column. I've got a custom user type that converts back and forth between the XML that lives in the database and a Map in memory.
Currently, I can store values in the Map such as lists, numbers, strings.
That works like a charm, but I'd
like to store entity references as well. In the XML, an entity reference would get collapsed down to something like:
Code:
<entityref entityname="person" id="342"/>
Stripping a primary key out of an entity is easy enough, but coming
back from XML, I need to instantiate the entity (or a proxy) so the resulting Map contains a usable Person.
I've hacked around a bit - by subclassing AbstractType, I've got access to a SessionImplementor during loading, but I'm clearly violating some sort of contract as I keep getting exceptions (that Hibernate reports are likely caused by session abuse). This happens when I call instantiate, internalLoad or immediateLoad.
Is there a safe way to do what I'm trying to do? Or is this impossible from a UserType?