• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JPA different tables, same entity-type

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pretty new to JPA, and I have run into a problem where we have several tables with entities of the same type.

Example:
Tables:
Itemtable2002
Itemtable2003
Itemtable2004
Itemtable2005
Itemtable2006
Itemtableybly (last year)
Itemtable (this year)

Entity for all is "Item"(same columns for all, but different data).

What I need to do, is to allow the user to choose what table to pull data from at runtime.

Any suggestions about how this can be done? The tables can not be altered.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Per-Morten,

can't you put your items in one table and add a year field? It would be simpler.
You select your items with a paramerized query that takes the year as in input param.

Regards
 
Per-Morten Lindanger
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As there are loads of programs allready accessing the tables, and since there's no record regarding where thoose programs are, changing the tables are not an option.

Anyway, I solved the matter by adding an interface. It turned out looking pretty neat. Thanks for the feedback.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
One other approach is to have a abstract entity class indicating Item and child entity classes for each of the years.
a table per entity is supported in jpa.

Please do let me know more about the 'adding an interface' approach, and how it worked.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic