# org.hibernate.MappingException: property \[id.companyId\] not found on entity

**URL:** <https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246>\
**Category:** Hibernate ORM\
**Created:** [June 5, 2020, 3:05pm UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246 "2020-06-05T15:05:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_Gould](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/todd_gould/32/1096_2.png) [@Todd\_Gould](https://discourse.hibernate.org/u/Todd_Gould)\
**Post date:** [June 5, 2020, 3:05pm UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/1 "2020-06-05T15:05:56Z")

</div>

Hi,

I am in the process of upgrading from Hibernate 5.0 to 5.3 and I am running into an unexpected issue.

My Entity class looks like this:

```auto
@Entity
@Table( name="USER_CUSTOMER_MAPPING",
	uniqueConstraints={ @UniqueConstraint( columnNames={ "USER_NAME", "COMPANY_ID", "CUSTOMER_ID" } ) })
@IdClass( UserCustomerMappingId.class )
public class UserCustomerMapping implements Cloneable, Serializable
{
	@Id
    @Column( name="USER_NAME", nullable=false, updatable=false )
    @Index( name="USER_CUSTOMER_MAPPING_USER_NAME_INDEX" )
    @NotNull
    private String userName = null;

    @Id
    @Column( name="COMPANY_ID", nullable=false, length=100 )
    @Index( name="USER_CUSTOMER_MAPPING_COMPANY_ID_INDEX" )
    @NotNull
    @Length( max=100 )
    private String companyId = null;

    @Id
    @Column( name="CUSTOMER_ID", nullable=false )
    @Index( name="USER_CUSTOMER_MAPPING_CUSTOMER_ID_INDEX" )
    @NotNull
    private String customerId = null;

  // rest has been abbreviated for brevity
}

```

My composite key class looks like this:

```auto
public class UserCustomerMappingId implements Cloneable, Serializable
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String userName = null;
    private String companyId = null;
    private String customerId = null;

    public UserCustomerMappingId()
    {
    	super();
    }

  // getters and setters omitted for brevity
}

```

The above works perfectly on 5.0, but encounters the below MappingException when run deployed on 5.3. This occurs while the PersistenceUnit is starting.

```auto
org.hibernate.MappingException: property [id.companyId] not found on entity [...UserCustomerMapping]

```

I have made no other source nor configuration changes, What am I missing or do I need to change to make the above work with 5.3 please?

---

<div class="post-metadata">

**Author:** ![Todd\_Gould](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/todd_gould/32/1096_2.png) [@Todd\_Gould](https://discourse.hibernate.org/u/Todd_Gould)\
**Post date:** [January 24, 2021, 7:55pm UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/2 "2021-01-24T19:55:28Z")

</div>

Kindly nudged as I am still stuck on this.

I have checked and doubled checked that all of the properties are identically declared between the @Entity and the @IdClass. I am not sure why it is looking for the companyId as a sub-attribute of “id” as there is no “id” in either the @Entity or @IdClass.

Is there any way to get Hibernate to provide more specific information regarding the specific source of the error (i.e. where it is looking for id.companyId from)?

Any and all help will be greatly appreciated.

---

<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:** [January 25, 2021, 10:33am UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/3 "2021-01-25T10:33:47Z")

</div>

Have you tried using Hibernate 5.4 already? Maybe this is a bug that was fixed already, just not backported to 5.3. If you still see this issue on 5.4, please create an issue in the issue tracker([https://hibernate.atlassian.net](https://hibernate.atlassian.net)) with a test case([hibernate-test-case-templates/JPAUnitTestCase.java at master · hibernate/hibernate-test-case-templates · GitHub](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)) that reproduces the issue.

---

<div class="post-metadata">

**Author:** ![ben\_yahia\_haithem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ben_yahia_haithem/32/1459_2.png) [@ben\_yahia\_haithem](https://discourse.hibernate.org/u/ben_yahia_haithem)\
**Post date:** [March 27, 2021, 2:48pm UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/4 "2021-03-27T14:48:45Z")

</div>

Helo @beikov I got a hibernate bug after adding Index annotation with hibernate 5 ,but was working fine with hibernate 4 , I created a jira issue [[HHH-14534] Hibernate index causing Runtime failure - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14534) , can you take a look please  
Thank you

---

<div class="post-metadata">

**Author:** ![Todd\_Gould](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/todd_gould/32/1096_2.png) [@Todd\_Gould](https://discourse.hibernate.org/u/Todd_Gould)\
**Post date:** [May 19, 2021, 12:14am UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/5 "2021-05-19T00:14:09Z")

</div>

I have recently discovered that the org.hibernate.MappingException can be avoided if I remove the `@Index` annotation from the `@Id` attributes in the `@Entity` class. This combination if `@Id` and `@Index` has worked well for me in Hibernate 5.0, but appears to be problematic in 5.3 (albeit not so obviously by the error message).

Can anyone shed any light on why this combination is now an issue? Additionally, I want t have a named index on these columns, how can I restore the combination of the two annotations without encountering the MappingException?

---

<div class="post-metadata">

**Author:** ![Todd\_Gould](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/todd_gould/32/1096_2.png) [@Todd\_Gould](https://discourse.hibernate.org/u/Todd_Gould)\
**Post date:** [May 19, 2021, 12:34am UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/6 "2021-05-19T00:34:43Z")

</div>

I would still like to understand why the combination of `@Id` and `@Index` is no longer working. However, I have found a way to still declare the desire to have these indexes by specifying them as part of the `@Table` annotation.

---

<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 19, 2021, 9:47am UTC](https://discourse.hibernate.org/t/org-hibernate-mappingexception-property-id-companyid-not-found-on-entity/4246/7 "2021-05-19T09:47:35Z")

</div>

As you can read in the issue ([[HHH-14534] Index annotation causing Runtime failure - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14534)) using `@Table` is the way to go and also a description of why this stopped working. Since the Hibernate `@Index` annotation is deprecated you should move away from this approach anyway.
