This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate OneToMany and ManyToOne Problem

 
Andreas Homann
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I've got two entities, Order and Component. An Order can have many Components. In the model class for the Component entity I set the relationship based on the foreign key "orderID" of the referenced table Order as follows:


The thing I wanna know is how I can access the orderID column in this component from the datatables framework. I only can access the object order and all other columns in this model:



I want to get the orderID in the Component model and not only the referenced object for the mapping. When I type "orderID" instead of order DataTables throws an exception "DataTables warning (table id = 'DataTables_Table_0'): Requested unknown parameter 'orderID' from the data source for row 0" because he only knows order. Any idea how to resolve it? I'm a beginner in Java, Hibernate and frameworks like datatables.
 
Aby Krishna
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the description, it seems like it is actually a Many-To-Many relationship between the Order and Component. An order can have multiple components and a component can be in multiple orders.

If the understanding is correct, there should be bidirectional relationship, a Many-To-Many annotation on Order (owning side) and Many-To-Many on Component (inverse side). With that you could fetch components from order and orders from components.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic