-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Using Views instead Tables
PostPosted: Fri Jul 11, 2008 11:53 am 
Newbie

Joined: Fri Jul 04, 2008 7:52 am
Posts: 8
is it possible to use database views for maping instead tables ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 12:58 pm 
Beginner
Beginner

Joined: Fri May 14, 2004 9:50 am
Posts: 28
Extract from the Hibernate doc "There is no difference between a view and a base table for a Hibernate mapping, as expected this is transparent at the database level (note that some DBMS don't support views properly, especially with updates). "

You can directly use the configuration of a table with a view.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 10:34 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed, mapping to views is supported!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 10:37 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If you're not updating or creating new rows in the view, you can simply map an entity to it. That's usually the easiest thing to do.

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.

Here's some info from Hibernate.org:

Quote:

Does Hibernate 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

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.