Skip to content
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

Property name change casues JaversException, we need 'alias feature' to register old names #178

Closed
TimSin opened this issue Jul 7, 2015 · 5 comments
Assignees

Comments

@TimSin
Copy link

TimSin commented Jul 7, 2015

In the process of developing an application I have had to change a property name in one of my classes. This now leads to an exception being thrown when I try to commit a snapshot of the object to Javers:

JaversException: PROPERTY_NOT_FOUND JaVers runtime error - property 'name' not found in class 'org.xxxx.ips.model.Course'
    org.javers.core.metamodel.clazz.ManagedClass.getProperty(ManagedClass.java:56)
    org.javers.core.metamodel.object.CdoSnapshotBuilder.withChangedProperties(CdoSnapshotBuilder.java:93)
    org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.deserializeChangedProperties(CdoSnapshotTypeAdapter.java:68)
    org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.fromJson(CdoSnapshotTypeAdapter.java:53)
    org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.fromJson(CdoSnapshotTypeAdapter.java:22)
    org.javers.core.json.JsonConverterBuilder$2.deserialize(JsonConverterBuilder.java:139)
    com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
    com.google.gson.Gson.fromJson(Gson.java:803)
    com.google.gson.Gson.fromJson(Gson.java:768)
    com.google.gson.Gson.fromJson(Gson.java:717)
    com.google.gson.Gson.fromJson(Gson.java:689)
    org.javers.core.json.JsonConverter.fromJson(JsonConverter.java:78)
    org.javers.repository.mongo.MongoRepository.readFromDBObject(MongoRepository.java:184)
    org.javers.repository.mongo.MongoRepository.getLatest(MongoRepository.java:241)
    org.javers.repository.mongo.MongoRepository.getLatest(MongoRepository.java:79)
    org.javers.repository.api.JaversExtendedRepository.getLatest(JaversExtendedRepository.java:100)
    org.javers.core.snapshot.GraphShadowFactory.createLatestShadow(GraphShadowFactory.java:32)
    org.javers.core.snapshot.GraphSnapshotFacade.createLatestShadow(GraphSnapshotFacade.java:22)
    org.javers.core.commit.CommitFactory.create(CommitFactory.java:76)
    org.javers.core.JaversCore.commit(JaversCore.java:60)
    .....

Clearing the mongo db of all data associated with the object clears the issue, but obviously this will be problematic with a live system. Is there a way that Javers can deal with property name changes to underlying objects without loosing all historical audit data associated with them?

@pszymczyk pszymczyk self-assigned this Jul 7, 2015
@pszymczyk
Copy link
Contributor

Hi

Currently Javers doesn't support property name changes, but I think it could be very nice feature if you have some ideas how to deal with it we could discuss it and prepare some solution :), for now you can execute some script updating Javers sctructures or change your class name and store changes from the beggining.

@bartoszwalacik
Copy link
Member

We could introduce aliases for properties and also for class names, configured in JaversBuilder

@TimSin
Copy link
Author

TimSin commented Jul 9, 2015

From an audit point of view, as long as the old property data was available in historical snapshots I would be happy. I guess that may make diffs more difficult, though to me it would seem logical to treat the now missing data as null and maybe store a Change to record when it was noticed that the old property was no longer present.

I haven't browsed the source extensively so I'm not too familiar with Javers internals, but looking at the ManagedClass source, I wonder if there is a way to make it aware of class versions? I was thinking along the lines of storing a Map of per-class property names keyed by Serial Version ID somewhere, with the data persisted somewhere in the schema? The obvious downside to this is that versioned classes using this feature would have to be Serializable.

The property alias idea sounds like a good feature, though would it cope with property deletion as well as re-naming?

@bartoszwalacik
Copy link
Member

Aliases could be use to handle renames. For example if you rename 'name' to 'forename' , you will add an alias 'name' to property 'forename'. Not sure about this class versioning idea. I think you can have only one class version loaded at a time.

@bartoszwalacik bartoszwalacik changed the title Property change casues JaversException: PROPERTY_NOT_FOUND Property name change casues JaversException, we need 'alias feature' to register old names Jul 18, 2015
bartoszwalacik added a commit that referenced this issue Oct 19, 2015
bartoszwalacik added a commit that referenced this issue Oct 19, 2015
minor refactoring, makings things package-private
@bartoszwalacik
Copy link
Member

good news, JaVers 1.4.0-RC1 is ready, it gives you @TypeName annotation
and support for domain classes refactoring.
Check it out and give me feedback, does it solve your issue?

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

No branches or pull requests

3 participants