- This topic has 5 replies, 3 voices, and was last updated 17 years, 7 months ago by Riyad Kalla.
-
AuthorPosts
-
jcorbin4607MemberI have a simple many-to-many relationship.
I have a customer and address table with another table that links them together using foreign keys.
When I generate the mappings from the Hibernate Reverse Engineering tools, it generates the Set designation just fine in my Customer mapping.
When I execute an insert of a customer with an address, the customer and address table do show the rows correctly. The problem is that there is now row generated in the link table. Not sure why the row doesn’t get inserted or how to correct the mapping.
I selected all 3 tables in the reverse engineering wizard and made sure the detect many-to-many was checked.
I am running MyEclipseIDE 5.5 M2 on my Intel Mac, using Java 5.
Brian FernandesModeratorjCorbin,
Were the mapping files generated correct? You should see the <many-to-many> element in both your Customer and Address mapping files.
Also there should be no POJO or mapping file generated corresponding to the link table. If this is not the case then there is a mapping issue.When I execute an insert of a customer with an address, the customer and address table do show the rows correctly. The problem is that there is now row generated in the link table. Not sure why the row doesn’t get inserted or how to correct the mapping.
Where exactly are you checking the rows – in the database with a select query? If so, are the other entities being correctly persisted in your tables?
jcorbin4607MemberWere the mapping files generated correct? You should see the <many-to-many> element in both your Customer and Address mapping files.
Also there should be no POJO or mapping file generated corresponding to the link table. If this is not the case then there is a mapping issue.
Yes, there are many-to-many tags in both the customer and address mapping. There was no POJO or mapping made for my link table. I did have to manually add the cascade=”all” attribute to these mappings.
Here is the <set> tag for each of the mappings, first customer mapping then followed by address,
From Customer.hbm.xml…
<set name=”addresses” table=”link_cust_addr” catalog=”reservation” cascade=”all”>
<key>
<column name=”cust_id” not-null=”true” unique=”true” />
</key>
<many-to-many entity-name=”com.receptrix.hibernate.Address”>
<column name=”addr_id” not-null=”true” />
</many-to-many>
</set>From Address.hbm.xml…
<set name=”customers” inverse=”true” table=”link_cust_addr” catalog=”reservation” cascade=”all”>
<key>
<column name=”addr_id” not-null=”true” />
</key>
<many-to-many entity-name=”com.receptrix.hibernate.Customer”>
<column name=”cust_id” not-null=”true” unique=”true” />
</many-to-many>
</set>Where exactly are you checking the rows – in the database with a select query? If so, are the other entities being correctly persisted in your tables?
I performed a SQL Query within DBVisualizer to verify that the customer and address tables did indeed have the correct data after the save operation. I also verified that the link_cust_addr table was empty.
I also enabled the debug output so I could see the SQL being generated for the inserts and in each case the SQL was correct for the customer and address tables but no debug output showed up for the link_cust_addr table.
jcorbin4607MemberIs there anyway to run hbm2ddl from MyEclipseIDE Installation?
I think it would be interesting to see what hbm2ddl generates from my current mappings. I can use this information to see how it compares to my existing table definitions.
J
jcorbin4607MemberCould I get some follow-up from the forum support engineers on this issue? It shouldn’t be this difficult to setup a many-to-many relationship using Hibernate within the MyEclipseIDE (5.5M2) environment.
Riyad KallaMemberI’m sorry, we are completely swamped on the 5.5 release-testing right now and Brian doesn’t have any bandwidth left to do support at the moment. Let me ping him in a couple days for you to see if he can follow up with you.
-
AuthorPosts