users@jaxb.java.net

Re: HibernateProxy causes class type mismatch

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 12:30:07 -0700

Sorry for being very late, but I believe I posted my answer to your
question in the forum (just so that other people know where to search.)

vr.sundar wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com