Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Can I use eclipselink to get the differences between two objects?

If you wish to go under the covers a little their is an API,
DeferredChangeDetectionPolicy.createObjectChangeSetThroughComparison(), that
will return an ObjectChangeSet listing the changes between the two objects.

Is it possible to make it consider @OneToMany mappings also?

It will report a difference no matter what I put into the @OneToMany set, even if the objects themself are equal if passed into the  createObjectChangeSetThroughComparison method.

I would like to work with a object graph rather than with individual objects.

Under the covers api's are not a problem.

I currently do it like this:

    private JpaEntityManager entityManager;

    private final ObjectChangePolicy objectChangePolicy = new DeferredChangeDetectionPolicy();

    public ObjectChangeSet compare(final AbstractEntity original, final AbstractEntity copy) {
        ObjectChangeSet objectChangeSet = this.objectChangePolicy.createObjectChangeSetThroughComparison(original, copy,
            (UnitOfWorkChangeSet) this.entityManager.getUnitOfWork().getCurrentChanges(), false, (AbstractSession) this.entityManager
                .getActiveSession(), this.entityManager.getActiveSession().getDescriptor(original.getClass()));

        return objectChangeSet;



Magnus Heino wrote:
> Hi.
> Lets say I have
> Foo foo = new Foo(2);
> Foo foo2 = new Foo(3);
> Foo is an @Entity mapped by eclipselink.
> Can I somehow use components of eclipselink to compare foo and foo2, and
> get
> a list of differences?
> --
> /Magnus Heino

--- James Sutherland
 EclipseLink ,
Wiki: EclipseLink , TopLink
Forums: TopLink , EclipseLink
Book: Java Persistence
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

eclipselink-users mailing list


/Magnus Heino

Back to the top