In my application I get org.hibernate.exception.ConstraintViolationException when I include 2 or more lists of the same entity(@OneToMany relations) in one class.
@Embeddable
data class DocPresentation(
@OneToMany(cascade = [CascadeType.ALL])
var billOfLadingComments: List<Comment>?,
@OneToMany(cascade = [CascadeType.ALL])
var invoiceComments: List<Comment>?,
...
@Entity
@Table(name = "Comment")
data class Comment(
@Column(name = "date")
var date: Date?,
@Column(name = "message")
var message: String?,
@Embedded
var sender: Company?
) {
constructor() : this(null, null, null)
@Id
@GeneratedValue
@Column(name = "database_id")
var databaseId: Int? = null
}
The relation is unidirectional, so an intermediary table is created which holds the ids of the related entities. In this case it includes the id of the embedding entity of DocPresentation
, and 2 colums: billOfLadingComments_database_id
and invoiceComments_database_id
.
When I comment one of the lists the application works properly. How can I resolve the exception?