# Relations issue after migrating to hibernate 6.X.X.Final

**URL:** <https://discourse.hibernate.org/t/relations-issue-after-migrating-to-hibernate-6-x-x-final/9111>\
**Category:** Hibernate ORM\
**Created:** [February 28, 2024, 9:32am UTC](https://discourse.hibernate.org/t/relations-issue-after-migrating-to-hibernate-6-x-x-final/9111 "2024-02-28T09:32:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anasterion](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anasterion](https://discourse.hibernate.org/u/anasterion)\
**Post date:** [February 28, 2024, 9:32am UTC](https://discourse.hibernate.org/t/relations-issue-after-migrating-to-hibernate-6-x-x-final/9111/1 "2024-02-28T09:32:21Z")

</div>

After migration from hibernate 5.6.12.Final to 6.X.X.Final, following model stopped working:

```auto
@Entity
public class Person {

    @Id
    @Column(name = "USER_ID")
    private String userId;

    @OneToOne(optional = false, fetch = FetchType.EAGER)
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
    private Employee employee;
}

```

```auto
@Entity
public class Employee implements Serializable {

    @Id
    @Column(name = "USER_ID")
    private String userId;

    @Column(name = "PARTNER_ID")
    private Long partnerId;

    @OneToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "PARTNER_ID", referencedColumnName = "PARTNER_ID")
    private List<Roles> roles;
}

```

```auto
@Entity
public class Roles implements Serializable {
    
    @Id
    @Column(name = "PARTNER_ID")
    private Long partnerId;
    
    @Id
    @Column(name = "CODE")
    private String code;
    
    @Column(name = "NAME")
    private String name;
}

```

When launching application face following error:

```auto
Caused by: org.hibernate.AnnotationException: An association that targets entity 'Employee' from entity 'Roles' has no '@JoinColumn' referencing column 'user_id'
        at org.hibernate.boot.model.internal.TableBinder.bindPrimaryKeyReference(TableBinder.java:640)
        at org.hibernate.boot.model.internal.TableBinder.bindExplicitColumns(TableBinder.java:589)
        at org.hibernate.boot.model.internal.TableBinder.bindForeignKey(TableBinder.java:567)
        at org.hibernate.boot.model.internal.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:2650)
        at org.hibernate.boot.model.internal.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:1690)
        at org.hibernate.boot.model.internal.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:1588)
        at org.hibernate.boot.model.internal.CollectionBinder$1.secondPass(CollectionBinder.java:1577)
        at org.hibernate.boot.model.internal.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:45)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1815)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1774)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:331)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1432)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503)
        at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1822)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1771)

```

Issue is reproducable on version 6.0.0.Final, 6.2.2.Final and also tried latest 6.4.4.Final. Can you please assist with this problem?

---

<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:** [February 28, 2024, 9:52am UTC](https://discourse.hibernate.org/t/relations-issue-after-migrating-to-hibernate-6-x-x-final/9111/2 "2024-02-28T09:52:27Z")

</div>

Please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.
