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.