S
S
Splite2017-05-29 14:01:22
Java
Splite, 2017-05-29 14:01:22

How to follow two way @OneToMany in JPA?

Hello, there are two entities

@Entity
open class Member() {
    @ManyToOne(optional = false)
    open var group: Group? = null
}

@Entity
open class Group() {
    @OneToMany(mappedBy = "group", fetch = FetchType.EAGER)
    open var members: MutableList<Member> = ArrayList()
}

Kotlin code, but nothing fundamentally changes for java
//сначала rank.group это oldGroup
rank.group = newGroup

In such a situation, should rank be added to newGroup.members? And should it disappear from oldGroup.members? If not, what is the right way to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kosarev, 2017-05-29
@Splite

If you save the rank (which, as I understand it, is of the Member class), then yes, the members set will change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question