-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Morphia annotations #62
Comments
Hi Javers correctly recognized Morphia annotations - recognized StringRange as Entity and looking for property anootated as @id. Currently Javers can recognize objects as: so there is two solutions in this case, you can add property annatated as @id, or remove @entity annotation. StringRange is typical Value Objects so i would advice to remove @entity annotation, but i don't know is Morphia required @entity annotation to store objects in db? |
Yes, Morphia requires @entity to save it in the database. I have a complex tree of objects that I am eventually trying to get audit trail for. I took one of the lower level simple ones to build the test. @id is already used on many of my entities that have identifiers and Javars seems to handle them fine. However the StringRange object above is a Value Object so it does not have an identifier. So I can't remove @entity and there is no identifier. Is there any other option? |
I think we should change the algorithm of recognizing classes as entities, i will try to reproduce your case in a test and resolve this problem |
Sounds great. Let me know if you need anything else from me. |
Hi Chuck Obvioulsly we need priorities in Javers config. Give us a while, we'll check how fast we can add these feature |
Thanks. On a side note, Morphia also has its own @id annotation, but I think Jarvers was picking that up correctly. I will test again and let you know. |
I take that back. Using the Morphia @id annotation give a strange error about _time. This is the most basic example of using Morphia. All top-level Morphia entities need an @id annotated field. import org.bson.types.ObjectId;
import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
import org.javers.core.diff.Diff;
import org.junit.Test;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Property;
public class JaVersTest {
@Entity(noClassnameStored = true)
public class IdTest {
@Id
private ObjectId _id;
@Property
private String _name;
public IdTest() {
}
public IdTest(ObjectId id, String name) {
_id = id;
_name = name;
}
}
@Test
public void testBasic() {
Javers javers = JaversBuilder.javers().build();
ObjectId id = ObjectId.get();
IdTest obj1 = new IdTest(id, "Name");
IdTest obj2 = new IdTest(id, "New Name");
Diff diff = javers.compare(obj1, obj2);
System.out.println("diff: " + javers.toJson(diff));
}
} Gives this output:
The _time reference is from org.bson.types.ObjectId. |
StringRange class is definitely a ValueObject. |
You should map StringRange explicitly as ValueObject and Javers will ignore annotations. I've checked this. Use JaversBuilder.registerValueObject(Class) method: let me know if this solves your issue |
i mean it works well with current JaVers version, try: javersBuilder.registerValueObject(StringRange.class ) |
Tested and the StringRange example works fine when I register the value object. Is the second test example with @id behavior expected? |
Not sure which example do you mean? I've just our updated mapping documentation: I've reflected your case in the mapping hints section: In some cases, annotations could be misleading for JaVers. For example Morphia framework uses @entity annotation for each persistent class (even for ValueObjects). This could cause wrong JaVers mapping. As a solution, use explicit mapping with the JaversBuilder methods, as it has the highest priority. Can we close this issue? |
We suggest to close this issue and could you open another one for the second example because it looks like another issue. |
Ok..I will close this issue now. I am going to put together a more complete test for the second issue. If I cannot work it out, I will open another issue. Thanks for all your help. |
I am trying to test Javers with entities I save into a MongoDB database. I am using Morphia (https://github.com/mongodb/morphia) annotations to handle the saves and gets. Javers does not seem to like those annotations however. Here is a simple test I put together to show the problem:
This gives the following error:
However if I comment out only the "@entity" annotation it works:
I don't have the option of removing my Morphia annotations. Is there any other way to get this to work? Would it be possible to support Morphia annotations like the other ones that are supported?
The text was updated successfully, but these errors were encountered: