users@jaxb.java.net

Re: HibernateProxy causes class type mismatch

From: vr.sundar <vr.sundar_at_gmail.com>
Date: Wed, 11 Jul 2007 16:55:57 -0700

Hanson,

Thanks for the response. Hibernate3BeanReplicator.copy is what I'm
using currently. I am not sure how detached objects work. I'll check
up on that.

On 7/5/07, Hanson Char <hanson.char_at_gmail.com> wrote:
> How about converting a Hibernate persistent object to a simple pojo
> (or "detached" object in Hibernate terms), and then marshall the pojo
> into xml via JAXB ? This would give you a "clean" pojo, and bypass
> the proxy problem you encountered.
>
> You may consider using Hibernate3BeanReplicator#copy(T from) in
> Beanlib to achieve that:
>
> http://beanlib.sourceforge.net/
>
> It would work nicely if the object graph is not too big.
>
> Hanson Char
>
> On 7/5/07, vr. sundar <vr.sundar_at_gmail.com> 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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>