Search code examples
mongodbjakarta-eejpqlhibernate-ogm

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


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"),
    "disable_revision" : 0,
    "type" : "myMongoEvent",
    "title" : "ref title",
    "revision" : "0.0",
    "freeze" : false,
    "user_id" : 0,
    "syncdate" : ISODate("2018-12-22T23:41:22.951Z"),
    "undelable" : 0,
    "username" : ""
}

Query:

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?


Solution

  • The problem in this case is a bug in OGM. It happens when the @Column annotation is used on the attribute of an emebdded id. In this case, a query on that field will cause the exception.

    A fix has been provided and it will be available in the next release.