• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Adding additional data to join table

 
Peter Irmstadt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am working with JBoss Seam and Hibernate.

I do have two classes, List and Article. A list has some basic data (name, description, ..) and contains either none, one or more articles.

The list of Article objects inside the List class is implemented the following way:



This works fine, but I need to add another property to that single relation: A price of an Article. Every List may implement another price for the same Article and the prices between the Articles of one List might differ as well.

Is there any (hopefully Annotation based) solution to include the price property to the JoinTable? What (maybe other) solution would you propose?

Thank you in advance!
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can think only of one way but that will need changes to the database. Instead of the ManyToMany relation between List and Article, you can have an intermediate entity, something like Item. There will be a OneToMany association between List and Iten and a OneToOne association between Iten and Article. The Item class would store the price for that article in the list. Maybe there is another solution but this is all that I could think of...
 
Peter Irmstadt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:I can think only of one way but that will need changes to the database. Instead of the ManyToMany relation between List and Article, you can have an intermediate entity, something like Item. There will be a OneToMany association between List and Iten and a OneToOne association between Iten and Article. The Item class would store the price for that article in the list. Maybe there is another solution but this is all that I could think of...


this doesn't really matter. The only problem using this solution might be a possible bottleneck. A list will contain about 1000 items and if all items are loaded by additional joins the application might slow down - what do you think?

Caching isn't really possible here because the prizes are updated quite often and many lists are loaded simultanously.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic