@ManyToOne referencing entity with @OneToOne relationship as primary key could cause org.hibernate.AnnotationException depending on referenced entity or package name

Description

Relationship like below:

1 2 3 4 @Entity public class EntityA implements Serializable { @Id private int id;
1 2 3 4 5 6 7 @Entity public class EntityB implements Serializable { @Id @OneToOne @JoinColumn(name = "a_ref_id") private EntityA entityA;
1 2 3 4 5 6 7 8 @Entity public class EntityC implements Serializable { @Id private String code; @ManyToOne @JoinColumn(name = "b_ref_id") private EntityB entityB;

could cause org.hibernate.AnnotationException:

1 2 javax.persistence.PersistenceException: [PersistenceUnit: fail_package_pu] Error performing schema management Caused by: org.hibernate.AnnotationException: A Foreign key refering com.jpatest.fail.db.EntityB from com.jpatest.fail.db.EntityC has the wrong number of column. should be 0

Occurring of this error depends on package name and entity name

Environment

JDK Version: 1.8.0_161

Status

Assignee

Unassigned

Reporter

Bartlomiej Niemiec

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.4.2

Priority

Major