Uploaded image for project: 'Hibernate ORM'
  1. HHH-3502

getIdentifierMethod of BasicLazyInitializer does not match if method invoked through an interface with different return type

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Rejected
    • Affects versions: 3.3.1
    • Fix versions: None
    • Components: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      I have an entity interface,

      public interface IEntity {
      public Object getId();
      }

      and I have an entity, say User that implements this interface with an id method

      @Id
      public Long getId()

      { return id; }

      I can call getId() on an uninitialized proxy with,

      user.getId()

      however, if I call getId() in this way,

      ((IEntity) user)).getId()

      I get org.hibernate.LazyInitializationException: could not initialize proxy - no Session

      Looking at the code, BasicLazyInitializer has these lines,

      else if ( isUninitialized() && method.equals(getIdentifierMethod) )

      { return getIdentifier(); }

      the method.equals(getIdentifierMethod) returns false. The methods are not equal() because they have different return types (this is allowed in 1.5 with covariant return types).

      Hibernate should not use Method.equals(), but should instead use the code below (modified from Method.equals(Object)),

      public boolean equalsIgnoringReturnType(Method m1, Method m2) {

      if ((m1.getDeclaringClass() != m2.getDeclaringClass())

      { return false; }
      if (m1.getName() != m2.getName()) { return false; }

      Class[] params1 = m1.getParameterTypes();
      Class[] params2 = m2.getParameterTypes();
      if (params1.length != params2.length)

      { return false; }

      for (int i = 0; i < params1.length; i++)

      { if (params1[i] != params2[i]) return false; }

      return true;
      }

        Attachments

          Issue links

            Activity

              People

              • Votes:
                13 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: