Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate Mapping Issue in Many to Many Relationship

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Because of not appearing hibernate annotations by using hibernate reverse engineering, I have to define all classes based on database schemas in the database.

I defined all mapping class in the hibernate.cfg.xml.      



Here are the essential files including book,orders,orderdetail and orderdetailid.

Book class


Order class



Order Detail class


OrderDetailId class


Where did I do thing wrong.

How can I fix it?

I'll appreciate if you can help me.

Thank you.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the same, and this is the working version on my side. For your reference (I remove unrelated code such as some unrelated fields, constructors, equals, hashcode... for the brevity):

Book.java:



BookOrder.java:

 
Nam Ha Minh
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Continue...
OrderDetail.java:



OrderDetailId.java:



I hope this helps. I made that code based on these tutorials:

  • Hibernate Many-to-Many Association Annotations Example
    Hibernate Many-to-Many Association with Extra Columns in Join Table Example

  •  
    Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic