'Hibernate: Inherited Superclass with Composite ID

I have one JPA mapped superclass (joined inheritance strategy) that haves also a composite id class:

@Entity
@IdClass(MyCompositeIdClass.class)
@Inheritance(strategy = InheritanceType.JOINED)
public class MySuperClass {
  
  @Id
  private Long myFirstId;

  @Id
  private Long mySecondId;
}
public class MyCompositeIdClass implements Serializable {
  private static long serialVersionUID = 1L;


  @Id
  private Long myFirstId;

  @Id
  private Long mySecondId;
}

Therefore, I have an extension of this superclass and it's repository interface.

@Entity
@IdClass(MyCompositeIdClass.class)
public class MySubClass extends MySuperClass {

  private String myAttr;

}
@Repository
public interface MySubClassRepository extends JpaRepository<MySubClass, MyCompositeIdClass> {
}

And when executing findAll() repository interface method, Hibernate is executing the join query with the wrong fields comparison on the join clause (inverting both PK columns):

select 
   mysuperc0_.my_first_id
   mysuperc0_.my_second_id
   mysuperc0_1_.my_attr
from
   my_super_class mysuperc0_
inner join
   my_sub_class mysuperc_0_1_
on
   my_superc0_.my_first_id = mysuperc_0_1_.my_second_id
and
   my_superc0_.my_second_id = mysuperc_0_1_.my_first_id

Was it configuration issues or a framework internal problem? Tried to research about inheritance issues with composite id, but got only opened issues ran from exceptions, but, in this case, I do not have exceptions, it just returns an empty array.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source