0

I'm trying to make some auto-magic happen in java using proxies to track objects and saving them when a set* method is called. I started of using java's built in Proxy, and everything works just fine, but from what I can understand I need a interface for every model, which is something that I'm trying to avoid.

This is where CGLIB comes in, it allows me to create proxies of my models without the use of interfaces. BUT, how can I now retrieve the original object, the one I am trying to save?

The optimal solution to be would be something like the EntityManager interface used by hibernate, where you keep your original object, but it is still tracked.

atomman
  • 2,510
  • 1
  • 16
  • 27
  • Do you mean that you're trying to persist an object using standard Java serialization but you're having issues serializing classes instrumented with CGLIB? – Ivan Koblik Oct 02 '12 at 08:39
  • I'm using xstream to serialize the object to xml, but the problem is that I cannot reach the model object from within the intercept method of the MethodInterceptor class. I hope that made it somewhat more clear. – atomman Oct 02 '12 at 09:14

1 Answers1

0

MethodInvocation interface specifies only one method that takes MethodInvocation as an argument. MethodInvocation has several methods to retrieve objects that are being acted upon: getStaticPart, getThis. Have you tried calling them?

As a shameless plug, you could actually use Hibernate together with Xstream. Here's my blog post about Xstream persister. But in this case Xstream is used to save fields in XML format in a database.

Ivan Koblik
  • 4,285
  • 1
  • 30
  • 33
  • I've read through your blog post, and it seems like a really cool thing. Though not the thing I'm looking for, we're trying to avoid the use of a db. The other note seems really nice though, I've not tried the aopalliance's MethodInvocation. I will try it out now, and let you guys know how it went. :) – atomman Oct 02 '12 at 10:33