New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaVers runtime error - diff for Set of ValueObjects is not supported #191

Closed
lathy88 opened this Issue Aug 20, 2015 · 15 comments

Comments

Projects
None yet
4 participants
@lathy88

lathy88 commented Aug 20, 2015

Recently i got this error,

can not handle managed/back reference 'defaultreference' in jackson for composite key
I googled alot but found the below option to use,

JsonManagedReference and JsonBackReference
Reference-> http://wiki.fasterxml.com/JacksonFeatureBiDirReferences

But my situation is,

Class Parent{
private int id;
@JsonManagedReference
Set childSet;
}

Class Child{
private ChildId childId;
private String name;
}

Class ChildId{
private int childKey;
@JsonBackReference
private Parent parent;
}
As you see, in the child class it has a composite key. I can not change this since it has relationship with DB.

Can anybody help me with this issue?

Note:
I'm using Jackson 2.4.3
I'm using Javers 1.2.9 for Object comparison

Update:

I removed all the JsonManaged and JsonBackReference annotations and added only JsonIgonre in Child as below,
Class ChildId{
private int childKey;
@JsonIgnore
private Parent parent;
}

After doing this I got the below error,

11:39:59,712 ERROR SetChangeAppender:46 - could not diff Field Set Child1; //declared in: Parent, JaVers runtime error - diff for Set of ValueObjects is not supported

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 22, 2015

well, first, JaVers doesn't know anything about Jackson and its annotations

The error you see - 'diff for Set of ValueObjects is not supported' means that you cannot manage Sets of ValueObject in Javers.
Try to map your entities (Parent and Child) as Entities.

@lathy88

This comment has been minimized.

lathy88 commented Aug 24, 2015

Hi Barto,
Thank you for your reply.
Could you please tell me what you mean by map your entities (Parent and Child) as Entities?

@bartoszwalacik

This comment has been minimized.

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Aug 24, 2015

@lathy88, reopen this ticket if our documentation won't help you

@arnzel

This comment has been minimized.

arnzel commented Jan 28, 2016

Why is diff for sets in value objects not supported ?

@andreasBerre

This comment has been minimized.

andreasBerre commented Jan 28, 2016

was just wondering the same thing, entities with sets of value objects should be a pretty common use-case?

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 28, 2016

The reason why JaVers doesn't support diff for Sets of ValueObjects is simple, we have no good idea how to do this :)

Imagine that you have two sets with ValueObjects.
By definition, ValueObjects dont have identifiers, how would you choose pairs to compare from left and right set? If you can suggest some good algorithm, we will do it.

@andreasBerre

This comment has been minimized.

andreasBerre commented Jan 28, 2016

heh, I see your point, alterations would per definition be impossible to track. Best you could do is consider the set itself a value object, and detect if it had changed (objects added/removed), would be useful in my use-case at least. Maybe as a SetChange?

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 28, 2016

true, new algorithm could detect only added/removed object.
Objects could be compared using kind of propertyEquals(o1,o2) method.
Of course, we dont wont n2 complexity, so first, we should calculate digest for each object (based on all its properties).

Digest heuristic is not obvious, we could try simply stringify and join all properties. But many Classes dont have good value-based toString()...

@andreasBerre

This comment has been minimized.

andreasBerre commented Jan 28, 2016

Hm, I'd have thought you might just use object.equals, and delegate all the problems to the individual developers? We won't be able to track individual property changes, but since a changed value object is per definition a new value object that sort of makes sense?

@andreasBerre

This comment has been minimized.

andreasBerre commented Jan 28, 2016

or that might be a bad idea, since the rest of Javers doesn't require you to implement equals... so stringify and join might be better...

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 28, 2016

Thats because many devs dont provide good equals() so we should not rely on it. We have ReflectionUtil.reflectiveToString() but it doesnt suit perfectly for this issue. Still, besides equals(), we need digest function (we dont want to fall into n2 complexity problem).
Fortunately, we can use shaDigest from MethodFactory...

@andreasBerre

This comment has been minimized.

andreasBerre commented Feb 11, 2016

Will you consider opening a issue for this?

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Feb 11, 2016

new Issue can be created easily, the problem is we don't have manpower to develop this ...

@bartoszwalacik bartoszwalacik added enhancement and removed question labels Feb 16, 2016

@bartoszwalacik bartoszwalacik self-assigned this Mar 2, 2016

bartoszwalacik added a commit that referenced this issue Mar 10, 2016

#191
failing tests and OwnerContext refactoring

bartoszwalacik added a commit that referenced this issue Mar 14, 2016

#191
all is green
@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Mar 16, 2016

fixed in release 1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment