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

Problems with Version 1.2 - support for Mongo 3.0 #146

Closed
mantithetical opened this issue May 5, 2015 · 14 comments
Closed

Problems with Version 1.2 - support for Mongo 3.0 #146

mantithetical opened this issue May 5, 2015 · 14 comments
Assignees

Comments

@mantithetical
Copy link

@mantithetical mantithetical commented May 5, 2015

JaversBuilder.javers().registerJaversRepository(mongoRepo).build() throws

com.mongodb.CommandFailureException: { "serverUsed" : "myDb:27017" , "ok" : 0.0 , "errmsg" : "unauthorized"}
    at com.mongodb.CommandResult.getException(CommandResult.java:76)
    at com.mongodb.CommandResult.throwOnError(CommandResult.java:140)
    at com.mongodb.DB.eval(DB.java:464)
    at org.javers.repository.mongo.MongoRepository.ensureSchema(MongoRepository.java:139)
    at org.javers.core.JaversBuilder.build(JaversBuilder.java:90)

The root cause appears to be the unauthorized migration in ensureSchema:

//schema migration script from 1.1 to 1.2
        BSONObject doc = snapshots.findOne();
        if (doc != null) {
            Object stringCommitId = ((Map)doc.get("commitMetadata")).get("id");
            if (stringCommitId instanceof String) {
                mongo.eval("db.jv_snapshots.find().forEach(function(snapshot){snapshot.commitMetadata.id = Number(snapshot.commitMetadata.id);db.jv_snapshots.save(snapshot);});");
            }
        }

The eval method has been deprecated as of mongodb version 3.0

I bypassed this issue by running the migration manually. However, after the first commit, subsequents commits throw a class cast exception.

javers.commit(username, myObject) throws

Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
    at org.javers.core.metamodel.object.CdoSnapshotBuilder.withChangedProperties(CdoSnapshotBuilder.java:92)
    at org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.deserializeChangedProperties(CdoSnapshotTypeAdapter.java:68)
    at org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.fromJson(CdoSnapshotTypeAdapter.java:53)
    at org.javers.core.json.typeadapter.commit.CdoSnapshotTypeAdapter.fromJson(CdoSnapshotTypeAdapter.java:22)
    at org.javers.core.json.JsonConverterBuilder$2.deserialize(JsonConverterBuilder.java:139)
@bartoszwalacik bartoszwalacik self-assigned this May 5, 2015
@bartoszwalacik bartoszwalacik changed the title Problems with Version 1.2 Problems with Version 1.2 - support for Mongo 3.0 May 6, 2015
@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 6, 2015

Both problems are caused by API changes in MongoDB. As far as I know, MongoDB 3.0 is not compatible with 2.x. Currently, Javers works with Mongo 2.6. I don't have quick solution how to support both Mongo versions in the same time. If we switch Javers to Mongo 3.0, it would brake existing clinets who use Mongo 2.x. Any ideas how to solve this?

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 6, 2015

think I should switch javers-persistence-mongo from MongoDB 2.6 to 3.0

@mantithetical
Copy link
Author

@mantithetical mantithetical commented May 6, 2015

The driver version up to 2.12.* seems to work fine. Anything after that is problematic. Switching to 3.0 sounds like a good idea.

@bgalek
Copy link
Contributor

@bgalek bgalek commented May 8, 2015

We decided to update mongo in javers-mongo-repository project, so it will support mongo 3, everyone still using older mongo will have to stick with javers-mongo-repository 1.2, stay tuned!

@mantithetical
Copy link
Author

@mantithetical mantithetical commented May 12, 2015

I am using mongo 2.6 and getting the Object to String class cast exception on javers commits. Don't you think that needs to be fixed? Otherwise, no one can use version javers 1.2.0.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 12, 2015

so you are using Mongo 2.6 or 3.0?
After running the migration script manually, what types you have under jv_snapshots.commitMetadata.id?

It should be changed from String do double, JaVers 1.2.0 expects doubles here

@mantithetical
Copy link
Author

@mantithetical mantithetical commented May 12, 2015

I am using Mongo 2.6 locally. I dropped both javers collections, so it's a fresh start. The first javers commit works fine as one would expect. Any subsequent commit fails with the ClassCastException. The problem is with javers 1.2.0 only.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 13, 2015

it means serious problem, i'll check it asap

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 13, 2015

that's confusing, I cannot reproduce this error on Mongo 2.6, could you send me first few documents from jv_snapshots collection ?

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 13, 2015

and the full stack trace?

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 14, 2015

I've checked if this bug occurs in our demo-app https://github.com/javers/javers-demo wich works with Mongo 2.6. App works fine. I cannot reproduce this bug

@mantithetical
Copy link
Author

@mantithetical mantithetical commented May 14, 2015

Let me get back to you with more details.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented May 24, 2015

JaVers 1.2.5 is released. We updated MongoDB Java Driver to 3.0
http://javers.org/documentation/features/#release-notes
check it out

@mantithetical
Copy link
Author

@mantithetical mantithetical commented May 27, 2015

I am sorry it took a while to get back to you. The problem was an unrelated one with a conflicting older version of gson in my project. I have upgraded Javers to 1.2.5 and so far so good!

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.