minhnhat
07/16/2022, 4:36 PMpost.tags.add(existedTag)
postRepo.save(post)
but It didn't workMikhail
07/16/2022, 4:36 PMminhnhat
07/16/2022, 4:38 PM@Entity
class Userr {
@Id
@GeneratedValue
var id: Long? = null
var name: String? = null
@OneToMany(mappedBy = "user", cascade = [CascadeType.PERSIST])
var roles: MutableList<Role> = mutableListOf()
}
@Entity
class Role {
@Id
@GeneratedValue
var id: Long? = null
var name: String? = null
@ManyToOne
@JsonIgnore
var user: Userr? = null
}
Mikhail
07/16/2022, 4:39 PMsaveAndFlush
? Do you use @Transactional
?minhnhat
07/16/2022, 4:40 PMTransactional
doesn't work
and I can't call saveAndFlush
Mikhail
07/16/2022, 4:56 PM@OneToMany
, because it's logically incorrect, a single post can have many tags and a tag itself can associate with multiple posts, this is @ManyToMany
. But, try this:
<http://existedTag.post|existedTag.post> = post
post.tags.add(existedTag)
postRepo.save(post)
minhnhat
07/17/2022, 7:23 AMval newAddress = Address()
newAddress.user = user // redundant
user.addresses.add(newAddress)
userRepo.save(user)
but if this is the only way to work in kotlin, I'm ok
BTW, thank you very much @MikhailJoinColumn
in OneToMany
and cascade = [CascadeType.All]