Hi there!
Given the following entity:
@Entity
public class Person implements Serializable {
@Id
@NaturalId
@Column(columnDefinition = "DECIMAL(39,0)")
private BigInteger id;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(
name = "Parent_Child",
joinColumns = {
@JoinColumn(name = "parent_id",
referencedColumnName = "id",
nullable = false,
unique = true,
foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
},
inverseJoinColumns = {
@JoinColumn(name = "child_id",
referencedColumnName = "id",
nullable = false,
unique = true,
foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
}
)
private Person child;
@JsonIgnore
@OneToOne(cascade = CascadeType.REFRESH, mappedBy = "child")
private Person parent;
}
When Hibernate tries to persist a Person entity, with another Person entity set as its’ child, it fails while trying to insert a record in the join table, because it uses the same parameter twice:
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement [No value specified for parameter 3]
[/* insert for com.person.Person */insert into Parent_Child (child_id,parent_id,parent_id) values (?,?,?)]