1

We want to implement a "versioning" feature in our Java project(JSF/EJB/JSF). Let me give an example:

       -----
       | A |
       -----
        1/\1
        /  \
      */    \*
    -----   -----
    | B |   | C |
    -----   -----    

The above diagram shows a simple object-graph with 3 objects i.e., A, B and C. B and C "is part" of A, any changes on A and/or B and/or C need to create a new version of A.

The question is, how to implement it, both in Java side and Database side ?

We got 2 solution so far and not settled yet:

SolutionA: very changes on the parts of A will cause a new deep clone of A, and this clone will be persistant via JPA to database as a new version. Pros: implementation is easy, cons: there are many redundancy(considering the case that the object graph is very big) in both java side and database.

SolutionB: only create changed part of A in database. Pros: no redundancy,DB performance may be better. Cons: this break the object-graph and we have to manually maintain the relations/references among objects. may drive development into a nightmare.

Any idea ?

John Wang
  • 4,562
  • 9
  • 37
  • 54
  • If this is a versioning system, should your model not be expressed in terms of Change, Version, etc.? –  May 28 '12 at 13:02
  • First of all, solution A would have better DB performance given the right index because it doesn't have to resolve the relationships when creating the object. Secondly, what is the purpose of versioning? to compare the difference? or just for recording keeping? – Chao Jun 04 '12 at 15:24

1 Answers1

0

A good framework exists for this in JAVA, take a look: Envers.

For performance issues, i'm not sure how the framework works (redundancy or no in database), but you'll avoid object clone.

J-Y
  • 96
  • 8