# Hibernate 5.3.7 issue for Composite keys

**URL:** <https://discourse.hibernate.org/t/hibernate-5-3-7-issue-for-composite-keys/6313>\
**Category:** Hibernate ORM\
**Created:** [May 9, 2022, 7:41am UTC](https://discourse.hibernate.org/t/hibernate-5-3-7-issue-for-composite-keys/6313 "2022-05-09T07:41:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaskaran\_Singh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jaskaran_singh/32/1880_2.png) [@Jaskaran\_Singh](https://discourse.hibernate.org/u/Jaskaran_Singh)\
**Post date:** [May 9, 2022, 7:41am UTC](https://discourse.hibernate.org/t/hibernate-5-3-7-issue-for-composite-keys/6313/1 "2022-05-09T07:41:43Z")

</div>

In our project, we have been using the hibernate xml configurations. Recently, I had upgraded my code from hibernate 3 to hibernate 5.3.7. Most of issues got resolved except below issue:

public class Employee implements Serializable{

private com.model.EmployeePK comp\_id;  
private String address;  
private String phoneNumber;

// getter setters created and constructor is present for above fields  
}

public class EmployeePK implements Serializable {

```
/** identifier field */
private Integer employeeName;
private Integer employeeNumber;

```

// getter setters created and constructor is present for above fields  
}

I had been using below query while referring to this table to select records:

String hql = "from com.model.Employee aTable where  
aTable.employeeNumber= :number ";

Here, in hibernate 3, this query works fine. However, in hibernate 5.3.7, this query throws an exception as hibernate not able to find employeeNumber( composite key) from the Employee entity.

To resolve the issue, i had to change the query and mention explicitly the composite key path in the query:

String hql = "from com.model.Employee aTable where  
aTable.compId.employeeNumber= :number ";

Above query works fine in newer version.

I am putting this observation in forum to understand why I am seeing this behavior and is there any major changes made in the context which allows developer to explicitly declare composite keys in queries.  
Is there any settings that can disable this behavior?

Looking forward to the discussion.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 9, 2022, 12:00pm UTC](https://discourse.hibernate.org/t/hibernate-5-3-7-issue-for-composite-keys/6313/2 "2022-05-09T12:00:39Z")

</div>

I am not aware of such a setting and didn’t know this “feature”. Hibernate has an implicit “id” attribute which can be used to refer to the primary key though.

---

<div class="post-metadata">

**Author:** ![Jaskaran\_Singh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/jaskaran_singh/32/1880_2.png) [@Jaskaran\_Singh](https://discourse.hibernate.org/u/Jaskaran_Singh)\
**Post date:** [May 12, 2022, 4:48am UTC](https://discourse.hibernate.org/t/hibernate-5-3-7-issue-for-composite-keys/6313/3 "2022-05-12T04:48:31Z")

</div>

Yes. I assumed there isn’t any special setting in hibernate for the same. Therefore, i had to scan my entire project to see if any composite key has been referenced incorrectly.

Thanks
