users@jaxb.java.net

HibernateProxy causes class type mismatch

From: vr.sundar <vr.sundar_at_gmail.com>
Date: Thu, 5 Jul 2007 11:08:56 -0700

Hi,

I posted this earlier on the jaxb forum but haven't got any response
yet. So also sending it to the user mailing list ... The problem I
face is this:

When I retrieve an instance of a jaxb annotated class using hibernate,
some of the child objects are represented by a hibernate proxy object.
This causes a problem in marshalling the properties because the types
of the objects don't match . For example if I have the following
annotations (assuming e1, e2 are subtypes of e)


XmlElements ({
@XmlElement( name="a", type="a.b.c.d.e1.class")
@XmlElement(name="b", type ="a.b.c.d.e2.class")
})
e someProperty;

the type of the retrieved object is something like
a.b.c.d.e1$$EnhancedByCGlib$$ and so it doesn't match the list of
types for this property. This causes some weird behaviour. The tag
names are different at diffferent runs. (In the jaxb source code this
is in SingleElementNodeProperty.serializeBody(). It goes into the last
(tt==null) block which has a comment saying this is acutally an error
but then picks the first tagName from the iterator. )

I'm wondering how to handle this problem. Is there a way for me to
plug in something that lets me configure how the java types are
matched?. Alternatively, can I do some kind of chaining of
XmlJavaAdapterType? Maybe define an adapter for HibernateProxy which
would then give out the actual object that can then be marshalled. I
looked through the api docs but couldn't find anything for that. Looks
like the output of the adapters have to be predefined pre-understood
types probably the list that I saw in teh jaxb spec. Is that correct?

Any help on this is greatly appreciated.

thanks
sundar