Hibernate Many to Many Relations Set Or List?

后端 未结 3 1461
失恋的感觉
失恋的感觉 2020-12-22 20:52

I have a many to many relationship at my Java beans. When I use List to define my variables as like:

@Entity
@Table(name=\"ScD\")
public class G         


        
3条回答
  •  难免孤独
    2020-12-22 21:20

    I know the question was made years ago but I wanted to comment on this topic, just in case someone is doubtful about the set vs list issue.

    Regarding lazy fetching, I think a bag (list without index) would be a better option due to the fact that you avoid retrieving all objects each time one is added to the collection to:

    • make sure a newly added one is unique, in case you are using a set
    • preserve order, in case you are using a list (with index)

    Please correct me if I'm mistaken.

提交回复
热议问题