Uploaded image for project: 'Hibernate Search'
  1. Hibernate Search
  2. HSEARCH-937

Search fails when loading associated entity with different ID type

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Out of Date
    • Affects Version/s: 3.4.1.Final, 4.0.0.Beta2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Suitable for new contributors:
      Yes, likely

      Description

      I have run into an issue after moving from Search 3.1 to 3.4.1 and later to 4.0.Beta2.

      The issue is that when loading an result entity from a hibernate search query the load fails if the result entity has an associated entity where the id types are dissimilar.

      For example if I have Company with an id type of Long and employee with id type of Integer and I search and the result is the company entity my search throws the following stack trace.

      caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
      	at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1909) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1880) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1758) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.doQuery(Loader.java:828) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.doList(Loader.java:2435) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.Loader.list(Loader.java:2271) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:121) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1484) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:373) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
      	at org.hibernate.search.query.hibernate.impl.CriteriaObjectsInitializer.initializeObjects(CriteriaObjectsInitializer.java:107) [hibernate-search-orm-4.0.0.Beta2.jar:]
      	at org.hibernate.search.query.hibernate.impl.QueryLoader.executeLoad(QueryLoader.java:91) [hibernate-search-orm-4.0.0.Beta2.jar:]
      	at org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:72) [hibernate-search-orm-4.0.0.Beta2.jar:]
      	at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:211) [hibernate-search-orm-4.0.0.Beta2.jar:]
      	at org.hibernate.search.jpa.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:147) [hibernate-search-orm-4.0.0.Beta2.jar:]
      	at com.domain.search.SearchUtil.search(SearchUtil.java:55) [classes:]
      

        Activity

        Hide
        cody.lerum Cody Lerum added a comment -

        Also all the entities load fine when they are queried via JPA/Hibernate Core (HQL, em.find(Company.class, 1L)) etc...

        Show
        cody.lerum Cody Lerum added a comment - Also all the entities load fine when they are queried via JPA/Hibernate Core (HQL, em.find(Company.class, 1L)) etc...
        Hide
        sanne Sanne Grinovero added a comment -

        Hi Cody, thank you very much for reporting this. Do you have a testcase to contribute? if so please attach a patch to the issue.

        Show
        sanne Sanne Grinovero added a comment - Hi Cody, thank you very much for reporting this. Do you have a testcase to contribute? if so please attach a patch to the issue.
        Hide
        cody.lerum Cody Lerum added a comment -

        I don't have a test case. I could probably repo it in a full EE6 AS7 project if that is helpful and post the git repo

        Show
        cody.lerum Cody Lerum added a comment - I don't have a test case. I could probably repo it in a full EE6 AS7 project if that is helpful and post the git repo
        Hide
        sanne Sanne Grinovero added a comment -

        if that's ok for you I'll extract a testcase from your example project, but if you have to create the project maybe it's easier to create a testcase only.. as you prefer.

        Show
        sanne Sanne Grinovero added a comment - if that's ok for you I'll extract a testcase from your example project, but if you have to create the project maybe it's easier to create a testcase only.. as you prefer.

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development