Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate Mapping Issue in Many to Many Relationship

 
Greenhorn
Posts: 12
  • 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

  •  
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!