“Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements”

前端 未结 5 1608
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 16:27

Good morning Stackoverflow,

I have the problem that it gives me the error:

Failed to create sessionFactory object.org.hibernate.AnnotationExcept

5条回答
  •  不知归路
    2021-01-31 17:19

    You can't save your collection fields as Concrete classes.

    Got this,

    As a requirement persistent collection-valued fields must be declared as an interface type (see Example 7.2, “Collection mapping using @OneToMany and @JoinColumn”). The actual interface might be java.util.Set, java.util.Collection, java.util.List, java.util.Map, java.util.SortedSet, java.util.SortedMap or anything you like ("anything you like" means you will have to write an implementation of org.hibernate.usertype.UserCollectionType).

    From Chapter 7. Collection Mapping.

    You can use below code to save a sorted set(KINDLY READ THE COMMENTS):

    @OneToMany(cascade=CascadeType.ALL) //Removed targetEntity, as you are already using generics.
    @JoinColumn(name="team_id") // Use this name as to show the presence of foreign key of EducationTeam in CoachGroup.
    @SortNatural // Make sure that your CoachGroup Entity has implemented Comparable interface which wii be used while sorting.
    private SortedSet coachGroups = new TreeSet<>();
    

提交回复
热议问题