1

Used this as my base 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.

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)
at utility.Utils.<clinit>(Utils.java:60)
at utility.Testing.main(Testing.java:21)

My AttendanceId class

@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

@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

@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

@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

@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
}

I think the inheritance is causing an issue. There are other classes/entities as well that extends the user entity. If anyone could help me find the problem that will be great. Thank you.

1 Answer 1

0

This issue is caused by the HHH-7135 Hibernate issue.

Sign up to request clarification or add additional context in comments.

8 Comments

I have added all the entities to the hibernate 5 package. You find anything that is wrong or is not to the standard let me know. I open to any kind of feedback. I have modified the test case in the class ORMUnitTestCase.java. Let me know if you find any issues. Thank you for helping. github.com/sukhvir41/hibernate-test-case-templates.git
Your project does not compile. There are missing imports and dependencies. Also, remove all the unnecessary entities. You need to add just the entities that are relevant to your issue.
I have removed the dependencies. If it still does not work let me know. thank you. github.com/sukhvir41/hibernate-test-case-templates.git
Still the same issues.
Try it now I have updated the entities and was able to reproduce it. Thank you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.