-->
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.  [ 1 post ] 
Author Message
 Post subject: Generation yields multiple copies of relationships
PostPosted: Mon Mar 08, 2010 2:32 pm 
Newbie

Joined: Mon Mar 08, 2010 1:59 pm
Posts: 2
I am new to Hibernate and am trying to port a php application to a
Flex/Spring/Blaze/Hibernate/Mysql environment. I'm using SpringSource Tool Suite (Eclipse) IDE with Hibernate tools.

An early step is to reverse engineer an existing MySQL 5 INNODB database with Hibernate tools.

Scenario:
There is a table for a particular genetic line of Zebrafish stock called the "stock" table.
There is also a table of genetic Mutations called "mutant".
There is a mapping table which maps stocks to mutants. One mutation can show in many stocks and one stock can have many mutations, this is represented in the "mapstock2mutants" table, which also has a few columns of information about the particular mutation in the particular stock (such as when it was identified and by whom)

I attempt to reverse engineer annotated domain code for this database. Most everything works fine. The "many to many" relationships like the one described above are mapped to two different many to one relationships, as expected. The problem is that each one is generated 4 times. So, for example, in the "Stock" object I see:

...
Code:
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
   public Set<Mapstock2mutants> getMapstock2mutantses() {
      return this.mapstock2mutantses;
   }
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
   public Set<Mapstock2mutants> getMapstock2mutantses_1() {
      return this.mapstock2mutantses_1;
   }
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
   public Set<Mapstock2mutants> getMapstock2mutantses_2() {
      return this.mapstock2mutantses_2;
   }
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
   public Set<Mapstock2mutants> getMapstock2mutantses_3() {
      return this.mapstock2mutantses_3;
   }

...
In the Mapstock2mutants class I get the expected
Code:
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "stockId", nullable = false)
   public Stock getStock() {
      return this.stock;
   }


This whole structure is repeated for the other side of the relationship between the Mutant class and the Mapstock2mutants class.

Additional notes. The first time I did this the code generator actually seemed to insert these duplicate relationships into the database for me using what seemed to be generated names starting with FK. I did not understand this and I deleted the additional relationships. They have stayed removed through subsequent re-generation of the code. Also, I have deleted and regenerated the clases and, of course I always get the same result.

I apologize if this is an old chestnut of a problem, but I cannot seem to find it documented.


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

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.