-->
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.  [ 6 posts ] 
Author Message
 Post subject: How do we map view in hibernate mapping file?
PostPosted: Wed Mar 28, 2007 7:38 am 
Newbie

Joined: Wed Mar 28, 2007 7:28 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

3.1.3:

How do we map view query in hibernate mapping file

This is my view.
create view con_metrix as
select trans_log.CONTRACT_NAME contractName,
avg(trans_log.PROVIDER_WS_TOTAL_TIME) averageTime ,
MAX(trans_log.PROVIDER_WS_TOTAL_TIME) maxRespTime,
MIN(trans_log.PROVIDER_WS_TOTAL_TIME) minRespTime,
COUNT(trans_log.STATUS) status from CON_TRANSACTION_LOG trans_log
GROUP by
trans_log.CONTRACT_NAME, trans_log.STATUS;
How can i map this to mapping xml

Thanks
Shanmugam.VE


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 9:19 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
hi,

map view as a normal table, no problems at all with that (i use it in oracle and hsqldb).

Though, i require only read-only access to the view.

reagrds, martin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 10:06 am 
Newbie

Joined: Wed Mar 28, 2007 7:28 am
Posts: 4
mar wrote:
hi,

map view as a normal table, no problems at all with that (i use it in oracle and hsqldb).

Though, i require only read-only access to the view.

reagrds, martin.


shanmugam wrote:

In the mapping xml how dose the select query is represented?



Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 10:07 am 
Newbie

Joined: Wed Mar 28, 2007 7:28 am
Posts: 4
shanmugam wrote:
mar wrote:
hi,

map view as a normal table, no problems at all with that (i use it in oracle and hsqldb).

Though, i require only read-only access to the view.

reagrds, martin.


shanmugam wrote:

In the mapping xml how dose the select query is represented? can some one give samples?



Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 3:24 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
sorry, i dont understand. what select query?

you create your view in the db, using sql db client of your choice. no hibernate here.

once your view is created, hibernate treats it as a normal table, so create a pojo with the properties you want to map to db columns and thats all.

bellow is my example mapping to one of my views -- snipped -- it is exactly the same as for table.

Code:
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="cz.facility.kp.app.ifactory">
 
  <class name="UcetniSpolecnost"
         schema="DB_JT"
         table="FC_VW_UCETNISPOLECNOST" lazy="false">
   
    <id name="id" column="id" type="long">
      <generator class="assigned"/>
    </id>
   
    <property name="ico" column="s_ico"/>

    <property name="nazev" column="s_nazev"/>
   
    <!-- can be used as FK to currency list -->
    <property name="idCisMena" column="s_mena"/>

    <!-- ... snip ... -->     

  </class>
 
  <query name="ifactory.UcetniSpolecnost.skupinyVykazovani"><![CDATA[
select skv from UcetniSpolecnost as skv where skv.esskKod is not null
]]></query>

  <query name="ifactory.UcetniSpolecnost.nocniZpracovani"><![CDATA[
SELECT us FROM UcetniSpolecnost AS us
WHERE us.nocniZpracovani = :nocniZpracovani
]]></query>

</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 10:22 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Shanmugam,

Mar is correct, you treat the View just as you would a table. Hibernate makes no distinction between a view and a table. If you were to map the view to a class using annotations, you would do something like this:

Code:
@Entity
@Table(name="con_metrix") //-- note we're using the view name!!!
public class ConMetrix {

  @Column(name="averageTime")
  int averageTime;

  @Column(name="maxRespTime")
  int maxRespTime;

[...]


Once the view is created in the database, you use it as you would a table.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.