Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Hibernate Mapping Issue in Many to Many Relationship  RSS feed

 
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
Eclipse IDE Hibernate 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
Eclipse IDE Hibernate 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!