Monday, July 14, 2008

Can Hibernate Map to a Database View Without A Primary Key Defined?

If you're not updating or creating new rows in the view, you can simply map an entity to the db2 view or oracle view. That's usually the easiest thing to do when mapping db views.

And while views don't have primary keys it is very easy to define a view that has a surrogate key. I'd recommend this to easy the pain of mapping it.

Hibernate and a Database View

Here's some info from Hibernate.org:

"Does Hibernate3 support database views?

Of course. From the point of view of Hibernate, a view is just like any other table (except that you might not be able to update or insert to a view). You can easily map a class to a view by specifying table="view_name".

In Hibernate3, you may even map an entity class to a SQL query result set using the subselect mapping element. This is useful if you are unable to define new views in your database. "

Using Hibernate and Database Views

My Hibernate Tutorials

My WebSphere Tutorials
My Sun Certification Mock Java Exams
My Portlet Development and Portal Administration Tutorials

No comments: