We're updating the issue view to help you get more done. 

@embededId containing a foreign key of an entity with inheritance giving an error on bootstraping

Description

Used this as my starting point: https://vladmihalcea.com/the-best-way-to-map-a-many-to-many-association-with-extra-columns-when-using-jpa-and-hibernate/

I have an entity named Attendance that has an and emebedid AttendacneId that has two columns lectureId (string) and studenId(UUID). The attendance entity also has other properties as well containing a ManyToOne relationship with student and lecture enity using the @MapsId on them. The student extends user entity where the id resides. now when I try to save anything I get this error.

1 2 3 4 5 6 7 8 9 10 java.util.NoSuchElementException at java.util.ArrayList$Itr.next(ArrayList.java:860) at org.hibernate.cfg.annotations.TableBinder.linkJoinColumnWithValueOverridingNameIfImplicit(TableBinder.java:724) at org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass.doSecondPass(PkDrivenByDefaultMapsIdSecondPass.java:37) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1684) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1641) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)

My AttendanceId class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @Embeddable public class AttendanceId implements Serializable { @Column(name = "lecture_fid") @Getter @Setter private String lectureId; @Column(name = "student_fid", columnDefinition = "uuid") @Getter @Setter private UUID studentId; public AttendanceId() {} }

My Attendance class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @Entity @Table(name = "attendance") public class Attendance implements Serializable { @EmbeddedId @Getter @Setter(AccessLevel.PRIVATE) private AttendanceId id; // other fields @ManyToOne(fetch = FetchType.LAZY) @MapsId("lectureId") private Lecture lecture; @ManyToOne(fetch = FetchType.LAZY) @MapsId("studentId") private Student student; }

My Student Class

1 2 3 4 5 6 7 8 9 10 @Entity @PrimaryKeyJoinColumn(name = "id") public class Student extends User implements Serializable, Comparable<Student> { // other fields @OneToMany(mappedBy = "student", fetch = FetchType.LAZY) @Getter private List<Attendance> attendances = new ArrayList<>(); }

My User class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @Entity @Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = {"email", "username"})}) @Inheritance(strategy = InheritanceType.JOINED) public abstract class User implements Serializable { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid") @Column(columnDefinition = "UUID") @Getter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC) private UUID id; // other fields. }

My Lecture Class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 @NamedNativeQueries( @NamedNativeQuery(name = "getLectureId", query = "select get_lecture_id()") ) @Entity @Table(name = "lecture") public class Lecture implements Serializable { @Id @Column(name = "id") @GenericGenerator(name = "lectureIdGenerator", strategy = "entities.LectureIdGenerator") @GeneratedValue(generator = "lectureIdGenerator") @Getter @Setter private String id; @OneToMany(mappedBy = "lecture", fetch = FetchType.LAZY) @Getter private List<Attendance> attendances = new ArrayList<>(); // other fields }

Test case: https://github.com/sukhvir41/hibernate-test-case-templates
Forum link: https://discourse.hibernate.org/t/embededid-containing-a-foreign-key-of-an-entity-with-inheritance/2334

Environment

java 1.8, postgresql and H2(test case)

Status

Assignee

Unassigned

Reporter

Sukhvir Thapar

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.4.1
5.4.0

Priority

Major