-->
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.  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: reveng of the many-to-many?
PostPosted: Thu Sep 28, 2006 6:33 pm 
Beginner
Beginner

Joined: Sat Sep 23, 2006 5:44 pm
Posts: 22
Location: Seattle, WA
I've been searching the forums and docs for hours... I'm using tools 3.2b7.

1) Is many-to-many reveng from a jdbc connection supposed to work or not in 3.2b7?

2) Is it supposed to output java and mapping files similar to what is shown in the tutorial for persons and events?

I keep getting two java classes for the join table, and no sets in either of the endpoint classes.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 12:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
See release notes http://opensource.atlassian.com/projects/hibernate/secure/ReleaseNote.jspa?version=10600&styleName=Html&projectId=10030&Create=Create
- Yes

or

http://opensource.atlassian.com/projects/hibernate/browse/HBX-132

True its not well documented.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 2:10 am 
Beginner
Beginner

Joined: Sat Sep 23, 2006 5:44 pm
Posts: 22
Location: Seattle, WA
Good to have the confirmation.

The box to enable many-to-many is checked in the code gen config; what else do I need to do; omit/include something in the reveng config?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
For it to work you need:

1) a table that is a pure many-to-many table
(e.g. only have 2 foreign keys that refer to 1 entity each, no other columns)

2) a db and jdbcdriver that supports reporting foreignkeys

done.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 7:09 am 
Beginner
Beginner

Joined: Sat Sep 23, 2006 5:44 pm
Posts: 22
Location: Seattle, WA
I'm using MySQL and their mysql-connector-java jar.

Code:
CREATE TABLE track (
  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  album_id INTEGER UNSIGNED NOT NULL,
  name VARCHAR(255) NULL,
  PRIMARY KEY(id),
  INDEX Track_FKIndex1(album_id)
)
TYPE=InnoDB;

CREATE TABLE track_has_artist (
  track_id INTEGER UNSIGNED NOT NULL,
  artist_id INTEGER UNSIGNED NOT NULL,
  PRIMARY KEY(track_id, artist_id),
  INDEX track_has_artist_FKIndex1(track_id),
  INDEX track_has_artist_FKIndex2(artist_id)
)
TYPE=InnoDB;

CREATE TABLE artist (
  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(20) NULL,
  PRIMARY KEY(id)
)
TYPE=InnoDB;


What I end up with is:

Artist.java (knows nothing about Tracks)
Track.java (knows nothing about Artists)
TrackHasArtist.java
TrackHasArtistId.java


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 7:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so you are most likely using and old mysql driver that assumes it has a db underneath that does not understand the concept of foreignkeys (which were the case for older versions of MySQL)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 6:01 pm 
Beginner
Beginner

Joined: Sat Sep 23, 2006 5:44 pm
Posts: 22
Location: Seattle, WA
max wrote:
so you are most likely using and old mysql driver


OK, somehow I did have an older version of the mysql connector/J. :( Upgraded that to version 5.0.3, and started from scratch, creating the hibernate.cfg.xml file and the console config, then the hibernate.reveng.xml file using the wizards. Same result as before.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 2:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
then enable debug log, run it from ant and show me the log - something is wrong (and mysql has a tendency to be really bad with respect to jdbc metadata)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: manytomany -> entitypojoclass.java
PostPosted: Tue Oct 03, 2006 4:26 pm 
Newbie

Joined: Tue Oct 03, 2006 3:57 pm
Posts: 3
Location: Netherlands
i, too, have the problem of not being able to correctly generate the ejb3 many-to-many annotation for two entities.

the setup is (i believe) correct: three tables, one the jointable with only two columns, the foreign keys using the mysql syntax for that.
When generating (with the 'detect many-to-many' checkbox ticked), two entities are generated (which is correct), both with a Set property pointing to the other entity.
I figure the problem is the mappedBy attribute in the manytomany annotation: after digging in the hibernatetools codebase i found the EntityPOJOClass.java (package org.hibernate.tool.hbm2x.pojo), more specific the
Code:
String generateCollectionAnnotation(Property property, Configuration cfg)
method.
It seems a copy/paste error of the one-to-many code above, because isn't a many-to-many relation always inverse? Which would mean that the mappedBy attribute is always not null, which means that the jointable code will never be executed and the annotation never added to the Set-getter.

So far my $0.02 on the subject ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you have a patch for it will be appreciated if you add it to the jira. thank you.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 6:19 pm 
Newbie

Joined: Tue Oct 03, 2006 3:57 pm
Posts: 3
Location: Netherlands
i'm not yet comfortable enough with the codebase to be able to fix this, but i will try to find the time in the coming few days!


Top
 Profile  
 
 Post subject: Similar issue on Postgres 8.1?
PostPosted: Thu Oct 05, 2006 10:39 am 
Newbie

Joined: Thu Sep 23, 2004 6:23 pm
Posts: 4
I believe I'm having a similar issue on Postgres 8.1. Here's the setup:

Hibernate tools 3.2 b7
Postgres 8.1.3
postgresql-8.1-407.jdbc3.jar
All other jars from tools package mentioned above

I first tried running this via ant, the gui version in eclipse didn't work either.

Here's the DDL for the many-to-many table:
Code:
CREATE TABLE conf.scaninst_sensorloc
(
  scaninst_id int4 NOT NULL,
  sensorloc_id int4 NOT NULL,
  CONSTRAINT scaninst_sensorloc_pkey PRIMARY KEY (scaninst_id, sensorloc_id),
  CONSTRAINT fk_scaninst_sensorloc FOREIGN KEY (scaninst_id)
      REFERENCES conf.scaninst (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk_sensorloc_scaninst FOREIGN KEY (sensorloc_id)
      REFERENCES conf.sensorloc (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;

(the tables on each end are very simple- just the pk and a few fields.

Here's the relevant code that was generated by the tools:
SensorLoc.java:
Code:
   @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "sensorlocs")
   public Set<ScanInst> getScaninsts() {
      return this.scaninsts;
   }


ScanInst.java:
Code:
   @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "scaninsts")
   public Set<SensorLoc> getSensorlocs() {
      return this.sensorlocs;
   }


So of course, when I try to run the hbm2ddl ant task (with an annotations config), I get the following error:
Code:
org.hibernate.AnnotationException: Illegal use of mappedBy on both sides of the relationship: com.lumeta.ips.report.data.model.conf.SensorLoc.scaninsts


Suggestions welcome if there's something I'm doing wrong, but seems to me like this might be a bug. If anyone wants me to run with -verbose or other tags, I'd be happy to do so.

Also- it'd be nice to not have to fix these mappings by hand (yes, I wish I were familiar with the hibernate code base, but I'm not... yet... :)

Thanks,
- Bucky


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it does not depend on the db, it is simply the template + the annotation code generator that has a bug.

And do remember that if there is a good (easy!) place to begin starting learning/contributing to hibernate it is within the tools :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 1:41 pm 
Newbie

Joined: Sun Oct 29, 2006 1:15 pm
Posts: 1
sleepwalk,

don't know if this'll help, but i wasn't seeing the <set> in the hbm.xml until i removed a table-filter exclude on the join table referenced in the <foreign-key> (the table-filter exclude was in the reveng.xml as a consequence of how my reveng.xml had evolved before I started working on the many-to-many). (using tools 3.2 beta 8 with hibernate 3.2.0.ga)


Top
 Profile  
 
 Post subject: Many to many genaration problem
PostPosted: Mon Oct 30, 2006 9:39 am 
Newbie

Joined: Thu Feb 02, 2006 7:20 am
Posts: 11
Hello

I read this posting, because I need also to work with many to many relations.

I have following db situation:
Table_A
Table_B
Table_A_B (join table), where there are only the two columns (id_A and id_B)
which identifies the composed primary key. Additional they single attributes are foreign key to the other two tables.


If I am launching hibernate tools, there will always be generated 4 java classes.
1) TableA.java
2) TableB.java
3) TableAB.java
4) TableABId.java (Composed id)

Now I have following questions:
- Must there be generated 3 and 4 as Java classes
- Why TableA.java contains as property a set of type TableAB and not a set of type TableB (the same is with TableB.java)

Thanks for any help


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 31 posts ]  Go to page 1, 2, 3  Next

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.