String Index Out Of Bounds Exception

I’m not sure where’s the problem here: I’m not able to retrieve this document in JPQL using the inner id

{
    "_id" : {
        "activity_id" : NumberLong(1),
        "id" : NumberLong(629364456)
    },
    "date" : ISODate("2018-12-22T23:41:22.951Z"),
    "sys_date" : ISODate("2018-12-22T23:41:22.951Z"),
    "type" : "myMongoEvent",
    "title" : "ref title",
    "revision" : "0.0",
    "freeze" : false,
    "user_id" : 0
}

I get the error

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Query query = entitymanager.createQuery("SELECT e.title FROM Event e WHERE e.id.id=:id");
query.setParameter("id",2046229248L);
List results = query.getResultList();

It works if I query for a plain string field like title .

It doesn’t if I query using the id of the compound index (I need a compound index).

I get the error java.lang.StringIndexOutOfBoundsException: String index out of range: -1 even if I query for a non existent title …I should simply get null results, why an exception is thrown?

I’m trying to replicate the problem but it seems to work on my machine.

We have a test that does something similar in our project: https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/queries/CompositeIdQueriesTest.java

These are the entities:

Would you be able to create a test case using these classes as a base? I tried to add a field called id of type long and see if it’s throw an exception but it didn’t.

Thanks

I created a minimal example to reproduce the error:


The code is pretty confusing I know, and there are few classes (Address, Zipcode) I don’t think they are involved in the problem.

(I use Eclipse on Ubuntu 16)

In order to reproduce the issue:

  • import in Eclipse :wink:
  • run CreateEvent (which persist 2 MyMongoEvent instances)
  • check and copy the random id of a document using the Mongo CLI
  • paste the random id in the query in SelectEvent at row #35
  • run SelectEvent

still stuck with this problem…I guess it’s an Hibernate bug with a compound index which contains a Long field. Somewhere there is a conversion problem between a Java Long type and the BSON Long type inside the document saved in mongodb

Hi, sorry about the delay with this answer. I was on holiday.
I’m checking the test case you provided but in the meanwhile it should work if you use a native query.

It seems you have found a bug. The problem is the @Column( name ="id") annotation on the embedded key.
I’m working on a fix for this.

I’ve created a Jira: https://hibernate.atlassian.net/browse/OGM-1551
I’ve also sent a PR so it should be fixed in the next release.

Thanks a lot for the feedback!

thanks, does the bugfix will be available in the next release soon?

The bugfix will be in the next release. I’m not sure now when we will release next.