2

I'm using Eclipselink to map my tables to entities. I have one big database table (actually it's view) with columns like groupId, groupName, categoryId, categoryName etc. I know it's redundand, but we're trying to minimize queries and it's dynamically created view.

The question is: How to map such table to several entities like Group, Category etc?

karolkpl
  • 2,189
  • 10
  • 39
  • 60
  • Just from theory: It should work if each of the entity class has at least the primary key column(s). Never tried it but also never heard that there must be a 1:1 mapping of tables and entity classes. – Matt Handy Oct 13 '11 at 11:22

1 Answers1

3

You would probably be better off mapping to the real tables and use query optimization to reduce your queries (such as join fetching and batch fetching)

See, http://java-persistence-performance.blogspot.com/2010/08/batch-fetching-optimizing-object-graph.html

If you really want to have several class map to the same table, you will need to have one Entity and make the rest Embeddables.

See, http://en.wikibooks.org/wiki/Java_Persistence/Embeddables

James
  • 17,965
  • 11
  • 91
  • 146