users@glassfish.java.net

Re: jpa and object duplication/cloning

From: <glassfish_at_javadesktop.org>
Date: Wed, 09 Jan 2008 16:35:22 PST

I'm going to effectively disagree with you that the JPA should handle the cloning of objects across EntityManagers. I'd say that it's spectacularly unqualified to support that, and there's a sound reason for it to do so.

Many folks, in many languages and environments, lament that there's rarely any kind of system provided "deep copy" functionality. It seems so easy, but a deep copy is just rampant with edge case, black hole, and implementation defined details that are effectively very difficult, if not impossible to capture, especially declaratively. Java has its Clonable interface, but it's still a shallow copy. The closest we really have (as I mentioned) is serialization, and many folks complain about that simply because it's too eager, for example.

You're asking the JPA to somehow have intimate knowledge of your domain and the context under which you're are cloning your object, and the general case and use cases for that are simply to wide and to varied.

In my experience, I've rarely had the need copy and duplicate object trees, particularly from one DB to another. Why I would want to duplicate all of the leaves of a tree thats nominally going to be stored in a normalized relational DB is, frankly, foreign to me.

So, I basically don't think any effort to solve this problem in some automatic or general way should be spent on the JPA. All of the cases are special cases, even the most basic.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=253092