aspose file tools
The moose likes Object Relational Mapping and the fly likes Mapping, entity, no table Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Mapping, entity, no table" Watch "Mapping, entity, no table" New topic
Author

Mapping, entity, no table

Bruno Frascino
Ranch Hand

Joined: Jul 22, 2003
Posts: 55
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!


--BJCK--
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
You can use a Hibernate <join> or a @SecondaryTable annotation.
Michael Swierczek
Ranch Hand

Joined: Oct 07, 2005
Posts: 95
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Mapping, entity, no table
 
Similar Threads
getting value from JTable
[JPQL] UNION
Gray fields javascript?
JTable Troubles.
Tool to generate a Class from MySQL table (Model Class for MVC Pattern)