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

Mapping, entity, no table

 
Bruno Frascino
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a class that needs to be mapped, I am using hibernate. But this class doesn't represent any specific table in the database, it contains fields from different tables. I have no idea how to do that, some help!?
Thanks!
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a Hibernate <join> or a @SecondaryTable annotation.
 
Michael Swierczek
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this helps, but you can map an SQL view to an entity in your code. I'm not sure which databases support SQL views, I use Postgres.

So if you have the tables
customer (customer_id, name)
transaction (transaction_id, customer_id, date, description)

You can do:


Then you can map 'most_recent_transaction_view' as an entity. The differences are that you want to treat it as read-only, because of course updates to an SQL view are not supported. You also want to map the entity relationships as simple Entity properties instead of Entities.

e.g. from the example above, you want to map the customer_id as a String or Long, and not as a Customer object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic