facebook

Hibernate Mapping using Built-In Tools

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #269387 Reply

    jcorbin4607
    Member

    I 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.

    #269416 Reply

    Brian Fernandes
    Moderator

    jCorbin,

    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?

    #269424 Reply

    jcorbin4607
    Member

    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.

    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.

    #269458 Reply

    jcorbin4607
    Member

    Is 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

    #269594 Reply

    jcorbin4607
    Member

    Could 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.

    #269601 Reply

    Riyad Kalla
    Member

    I’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.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Hibernate Mapping using Built-In Tools

You must be logged in to post in the forum log in