[JIRA] (HHH-15546) generate wrong ddl schema when use multi columns ManyToMany
by Andrea Boriero (JIRA)
Andrea Boriero ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15546 ( https://hibernate.atlassian.net/browse/HHH-15546?atlOrigin=eyJpIjoiMWQ3YT... )
Re: generate wrong ddl schema when use multi columns ManyToMany ( https://hibernate.atlassian.net/browse/HHH-15546?atlOrigin=eyJpIjoiMWQ3YT... )
Hi ningpp ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) ,
the ddl generated is correct, you are using the same table name of MiddleTable4 Entity as the @JoinTable of a @ManyToMany
@Entity
@Table(name = "main_multi_pks")
public class MainMultiPks {
....
@ManyToMany(targetEntity = DestTable4.class, cascade = { CascadeType.PERSIST }, fetch = FetchType.EAGER)
@JoinTable(name = "middle_table4",
joinColumns = {
@JoinColumn(name = "main_id1", referencedColumnName = "id1"),
@JoinColumn(name = "main_id2", referencedColumnName = "id2")
},
inverseJoinColumns = {
@JoinColumn(name = "dest4_id1", referencedColumnName = "id1"),
@JoinColumn(name = "dest4_id2", referencedColumnName = "id2"),
@JoinColumn(name = "dest4_id3", referencedColumnName = "id3")
}
)
private Set<DestTable4> destTable4s = new HashSet<>();
so these columns should be not null , the issue is the MiddleTable4 id column middle4_id}}does not correspond to any column of the join table, so when a{{MainMultiPks is saved the generated SQL insert statement for the Join table
insert into middle_table4 (main_id2, main_id1, dest4_id1, dest4_id2, dest4_id3) values (?, ?, ?, ?, ?)
contains all the columns specified by the @JoinTable but obviously not the MiddleTable4 id column and this causes the error ERROR: NULL not allowed for column "MIDDLE4_ID";
( https://hibernate.atlassian.net/browse/HHH-15546#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15546#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:b857cee )
2 years, 2 months