• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate - Adding additional data to join table

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic