]
Vitali Yemialyanchyk updated HBX-1093:
--------------------------------------
Attachment: simpleTest.zip
Missing inverseJoinColumn at ManyToMany relations with composite
keys
---------------------------------------------------------------------
Key: HBX-1093
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1093
Project: Hibernate Tools
Issue Type: Bug
Components: hbm2java
Affects Versions: 3.2.2, 3.2LATER
Environment: Hibernate Tools version 3.2.2.Beta1 and 3.2.4.CR1-N200810300202,
Oracle Database
Reporter: Nils Kelleter
Attachments: simpleTest.zip
Using the hbm2java tool for reverse engineering of database tables, the following problem
exists:
At ManyToMany relations with composite keys an inverseJoinColumn is missing.
Wrong code:
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "ET_MANY_TO_MANY_COMP_MAPPING",
joinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP1_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP11_ID", nullable = false, updatable
= false) },
inverseJoinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP2_ID", nullable = false, updatable =
false) })
public Set<EtManyToManyComp2> getEtManyToManyComp2s() {
return this.etManyToManyComp2s;
}
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "ET_MANY_TO_MANY_COMP_MAPPING",
joinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP2_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP22_ID", nullable = false, updatable
= false) },
inverseJoinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP1_ID", nullable = false, updatable =
false) })
public Set<EtManyToManyComp1> getEtManyToManyComp1s() {
return this.etManyToManyComp1s;
}
Correct code:
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "ET_MANY_TO_MANY_COMP_MAPPING",
joinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP1_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP11_ID", nullable = false, updatable
= false) },
inverseJoinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP2_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP22_ID", nullable = false, updatable
= false) })
public Set<EtManyToManyComp2> getEtManyToManyComp2s() {
return this.etManyToManyComp2s;
}
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "ET_MANY_TO_MANY_COMP_MAPPING",
joinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP2_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP22_ID", nullable = false, updatable
= false) },
inverseJoinColumns = {
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP1_ID", nullable = false, updatable =
false),
@JoinColumn(name = "FK_ET_MANY_TO_MANY_COMP11_ID", nullable = false, updatable
= false) })
public Set<EtManyToManyComp1> getEtManyToManyComp1s() {
return this.etManyToManyComp1s;
}
For reproducing this, you can use the following Oracle SQL scripts:
CREATE TABLE ET_MANY_TO_MANY_COMP1 (
ET_MANY_TO_MANY_COMP1_ID NUMBER,
ET_MANY_TO_MANY_COMP11_ID NUMBER,
FIELD VARCHAR2(10),
PRIMARY KEY (ET_MANY_TO_MANY_COMP1_ID, ET_MANY_TO_MANY_COMP11_ID)
);
CREATE TABLE ET_MANY_TO_MANY_COMP2 (
ET_MANY_TO_MANY_COMP2_ID NUMBER,
ET_MANY_TO_MANY_COMP22_ID NUMBER,
FIELD VARCHAR2(10),
PRIMARY KEY (ET_MANY_TO_MANY_COMP2_ID, ET_MANY_TO_MANY_COMP22_ID)
);
CREATE TABLE ET_MANY_TO_MANY_COMP_MAPPING (
FK_ET_MANY_TO_MANY_COMP1_ID NUMBER,
FK_ET_MANY_TO_MANY_COMP11_ID NUMBER,
FK_ET_MANY_TO_MANY_COMP2_ID NUMBER,
FK_ET_MANY_TO_MANY_COMP22_ID NUMBER,
FOREIGN KEY (FK_ET_MANY_TO_MANY_COMP1_ID,FK_ET_MANY_TO_MANY_COMP11_ID)
REFERENCES ET_MANY_TO_MANY_COMP1(ET_MANY_TO_MANY_COMP1_ID,ET_MANY_TO_MANY_COMP11_ID),
FOREIGN KEY (FK_ET_MANY_TO_MANY_COMP2_ID, FK_ET_MANY_TO_MANY_COMP22_ID)
REFERENCES ET_MANY_TO_MANY_COMP2(ET_MANY_TO_MANY_COMP2_ID, ET_MANY_TO_MANY_COMP22_ID),
PRIMARY KEY
(FK_ET_MANY_TO_MANY_COMP1_ID,FK_ET_MANY_TO_MANY_COMP11_ID,FK_ET_MANY_TO_MANY_COMP2_ID,FK_ET_MANY_TO_MANY_COMP22_ID)
);
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: