-->
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: map class to view
PostPosted: Mon Jul 28, 2008 1:30 pm 
Newbie

Joined: Tue May 22, 2007 2:12 am
Posts: 9
i need help to map a java bean to a sql view present in my database.
can any help in this regard?????


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 28, 2008 2:34 pm 
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 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.

http://hibernate3tutorials.blogspot.com/2008/07/can-hibernate-map-to-database-view.html

"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. "

http://www.hibernate.org/116.html#A28

_________________
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 28, 2008 2:46 pm 
Newbie

Joined: Tue May 22, 2007 2:12 am
Posts: 9
hi Cameron,

thanks for your reply.
i need to prepare a report for which i need to map my class to view.
i had written the following snippet in my hbm.

Code:
<class name="MyTestView" table="my_test_view">
  <id name="sr_no" type="long">
            <column name="SR_NO" />
            <generator class="native" />
        </id>
  <property name="name" type="string">
  <column name="NAME" length="45"></column>
  </property>
  </class>


the other thing that i tried was --

Code:
<class name="MyTestView" mutable="false" subselect="true">
  <subselect>
  select t.name,t.srno from test t
 
  </subselect>
  <synchronize table="test"/>
  <id name="srno"/>
  <property name="name"/>
  </class>


i always get my list size as 0 on firing criteria query for this class.
please correct and guide further.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 5:09 am 
Newbie

Joined: Tue May 22, 2007 2:12 am
Posts: 9
anyone..please help me in mapping views to my java class???


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.