@OnetoMany entity in @ElementCollection

413 Views Asked by At

I have 2 entities and 1 embeddable object :

@Entity
    class CourseDetails extends Course {
    @Id
    Integer id;
    @ElementCollection
        @CollectionTable(name = "course_section", joinColumns = @JoinColumn(name = "courseId"), foreignKey = @ForeignKey(name = "course_section_fk"))
        private List<CourseSection> courseSection;
    }
    
    @Embeddable
    public class CourseSection extends BaseBo {
    @OneToMany
        @JoinColumn(name="contentId")
        private Set<CourseContent> courseContent = new HashSet<>();
    }
    
    @Entity
    public class CourseContent {
    
        private static final long serialVersionUID = 1856738483334146418L;
        @Id
        private Integer contentId;
        private String contentSummary;
    }

I want to store coursesection as an embedded object of course and course_section should contain reference of course_content. I tried the above structure but it gives error :

@ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection

How to achieve this in spring boot-jpa ?

0

There are 0 best solutions below