-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: [hbm2java] Missing inverseJoinColumn at ManyToMany relations
PostPosted: Thu Oct 30, 2008 5:35 am 
Newbie

Joined: Thu Oct 30, 2008 5:07 am
Posts: 2
Using the hbm2java tool for reverse engineering of database tables, the following problem exists:
At ManyToMany relations with composite keys an inverseJoinColumn is missing. I think it seems to be a bug in the tool. I've tested it with the latest release 3.2.2.Beta1 and with the nigthly build HibernateTools-3.2.4.CR1-N200810300202

Wrong code:
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:
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_COMP1_ID", nullable = false, updatable = false) })
public Set<EtManyToManyComp1> getEtManyToManyComp1s() {
   return this.etManyToManyComp1s;
}

For reproducing this, you can use the following Oracle SQL scripts:
Code:
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)
);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 8:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Got a patch ?

I any case please report bugs like this in jira.

thanks

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 10:18 am 
Newbie

Joined: Thu Oct 30, 2008 5:07 am
Posts: 2
No, I have no patch, but I need one.

I've created a bug report in jira: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1093

Regards,

Nils


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.