| I am not allowed to edit the "Affect version" tag, but I can confirm that the bug is still present in version 5.3.5. If I have an entity class A with fields e.g. like: @Id private BigDecimal id; @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "primaryKeyOfOtherEntity", referencedColumnName = "notPrimaryKeyOfA") private Set<OtherEntity> otherEntities; The quoted code in the original bug report will first resolve the id as a BigDecimal from the correct field. getPersister( session ).getKeyType() will however return the type of the entity class itself, the following if condition !keyType.getReturnedClass().isInstance( id ) will be true and id will be overwritten with the instance of the entity class. When accessing the lazy proxy in the otherEntities field, it will eventually invoke BigDecimalTypeDescriptor.extractHashCode (based on the type of the real id) to get the hash code of the entity's key, but invoke the method with the entity class itself, which causes a ClassCastException to be thrown. There seem to be no feasible workaround for this issue. |