- I’m trying to create a map of students with the key being the period number and value being A list of all students with that period.
- The student object is marked as an entity.
@OneToMany(cascade = CascadeType.ALL)
@MapKey(name = "period")
@JoinColumn(name = "teacher_id")
private Map<Integer, List<Student>> students;
I also tried all this variation to students, but when i try to run the program. it shows the program having trouble creating the DB schema.
This one is orginzed by index being the period – 1.
@ElementCollection
@CollectionTable(name = "student_lists")
@Column(name = "student_list")
private List<List<Student>> students;
this is the main error im getting when i try to put a list in a list:
Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Association ‘com.tracer.model.Teacher.studentsByPeriod’ targets the type ‘java.util.List’ which is not an ‘@Entity’ type
Currently I created a seperate entity CustomStudentList that stores the list of students: List>. But I would like to use a map instead.
I tried different variations. and got to the CustomStudentList which works, but is not ideal.
Andrew Lam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.