facebook

Hibernate Many-toMany

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

    rbandeira
    Member

    Hi all again!

    I am very new in hibernate and java, and i would appreciate some help or example that someone have.

    I have a simple many-to-many association! Like Orders and Itens and we create a Orders_Itens table with two PKs like OrderID and ItensID.

    How can i create the mapping file for this situation?
    And the java class? How am i create this?!?!?

    Thanks,
    Raphael Bandeira.

    #231388 Reply

    Riyad Kalla
    Member

    Raphael,
    Please take a look at our quickstart guide here:
    http://www.myeclipseide.com/images/tutorials/quickstarts/hibernate/

    #231466 Reply

    ferguman
    Member

    Hi,

    The quickstart guide doesn’t tell one how to create classes that contain one to many associations to other classes (eg. Invoices with one or more Items on them). At least I don’t see how the quickstart guide could tell one since it only deals with one database table (that isn’t self referential ;-).

    Can the Hibernate tools help create java classes that contain sets/lists of other related classes?

    Thanks

    Joe

    #231585 Reply

    support-jeff
    Member

    joe –

    only the inverse side of a many-to-one relationship. many-to-many is not supported in the autogeneration tools at this time.

    #232287 Reply

    ahbrown41
    Member

    How about one to many as you mentioned? I selected all my tables in the explorer, the tables are connected via a few one to many foreign keys in MySQL. The generated code did not take this into account. What does it use to generate this mappings? Does it explore the foreign keys, is it name based?

    Thanks!

    #232323 Reply

    support-jeff
    Member

    No, the current version does not support any relationships other than the many-to-one side of things.

    #232341 Reply

    ahbrown41
    Member

    Sorry Jeff, just to be clear. I mentioned a one to many relationship and you mentioned a many to one relationship. As far as I understand it, these are the same depending on the how you look at it. From the db foreign key they are the same, one address can have one country but one country can have many addresses right? So if this is supported, what mechanism does it use for doing this link? Foreign keys or column names? Or, does it only support doing a mapping for a single table and does not take into account the relations of other tables?

    Thanks.

    #232342 Reply

    ahbrown41
    Member

    To be clear, I am not talking about many to many relationships in any way 🙂 I understand that is not supported.

    #232357 Reply

    support-jeff
    Member

    Currently the tool only supports mapping relationships as a many-to-one entry in the mapping file for the table that has the FK, not its inverse in the related table (the one-to-many collection association). If you need more info on the difference, please take a look at the documentation on the hibernate web site:

    http://www.hibernate.org/hib_docs/reference/en/html/

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Hibernate Many-toMany

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