XStream

Sanitizing hibernate proxied objects ( GetOutOfMyPojo)

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.4
  • Component/s: None
  • Labels:
    None

Description

This is a known problem that objects loaded via hibernate are
heavily proxied by CGLIB, and thus not really serializable.

Since hibernate is de-facto O/R mapping standard, this is pretty common
that such objects have to be sent to remote clients via SOAP or other
means, and somehow this is not working
( See for example: http://www.mojavelinux.com/blog/archives/2006/06/hibernate_get_out_of_my_pojo/ )

I played around with mappers / converters and it seems that I got it working.
Since my knowlege about xstream internals is pretty limited, I would like developers to review
( and maybe make it better ) my solution

Attached file is quick & dirty testcase, adapted from jtec-user
( http://www.sourceforge.net/projects/jtec/ ,
svn:https://jtec.svn.sourceforge.net/svnroot/jtec/jtec-user )

Issue Links

Activity

Hide
Geoffrey De Smet added a comment -

Do note that if you're sanitizing objects, you're also removing the PersistentBag (implements List) etc implementations.
AFAIK the PersistentBag implements remembers what objects have been deleted.
So when you cascade to a bag(=List), it's probably a performance gain (and even optimistic locking check too?) to come back with the modified detached PersistentBag's instead of a brand new ArrayList.

Nevertheless, sanitizing will probably work.

Show
Geoffrey De Smet added a comment - Do note that if you're sanitizing objects, you're also removing the PersistentBag (implements List) etc implementations. AFAIK the PersistentBag implements remembers what objects have been deleted. So when you cascade to a bag(=List), it's probably a performance gain (and even optimistic locking check too?) to come back with the modified detached PersistentBag's instead of a brand new ArrayList. Nevertheless, sanitizing will probably work.
Hide
Geoffrey De Smet added a comment -

PS: How do you deal with proxy's?

A proxy is just a "wrapper around the id" (which was a foreign key in the referencing object).

Say I have A -> B -> C -> D (all explicitly LAZY mapped) and I select A left join fetch B, but I don't eager fetch C.
Than A has a B and that B has a proxy of C.
Note that you'd have to LAZY map a ManyToOne association to test this (which is actually recommended by the hibernate guys).

Show
Geoffrey De Smet added a comment - PS: How do you deal with proxy's? A proxy is just a "wrapper around the id" (which was a foreign key in the referencing object). Say I have A -> B -> C -> D (all explicitly LAZY mapped) and I select A left join fetch B, but I don't eager fetch C. Than A has a B and that B has a proxy of C. Note that you'd have to LAZY map a ManyToOne association to test this (which is actually recommended by the hibernate guys).
Hide
Eric Raymond added a comment -

Is this really a duplicate of http://jira.codehaus.org/browse/XSTR-226?

It seems like the former is dealing with the hibenrate collection classes.

This bug seems to be related to the fact that proxied objects in hibernate also use CGLIB and add their own callbacks.

Show
Eric Raymond added a comment - Is this really a duplicate of http://jira.codehaus.org/browse/XSTR-226? It seems like the former is dealing with the hibenrate collection classes. This bug seems to be related to the fact that proxied objects in hibernate also use CGLIB and add their own callbacks.
Hide
Joerg Schaible added a comment -

Support is now in trunk in separate module. Thanks to all contributions and remarks.

Show
Joerg Schaible added a comment - Support is now in trunk in separate module. Thanks to all contributions and remarks.

People

Vote (2)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: