-->
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.  [ 3 posts ] 
Author Message
 Post subject: N Select Queries fired for 1 call( N = no of rows in view)
PostPosted: Tue Feb 16, 2010 11:50 am 
Newbie

Joined: Tue Feb 16, 2010 11:31 am
Posts: 2
Hi all,

I have kept show_sql= true and i see that for one of my view that i created,when a hibernate query is called it is doing Multiple select queries. I have used Hibernate Reverse Engg to generate my Pojo's and Hbm files once i have created the view. I am unable to figure out where it might be wrong ..I am keeping my code pieces for your reference , If you can provide me some pointers i would highly appreciate it..
<Code Below>
Code:
CREATE OR REPLACE FORCE VIEW "INSTRUMENTS" ("ACCOUNT_NO", "INSTRUMENT_ID", "INSTUMENT_ID", "SYMBOL", "INSTRUMENT_SYMBOL", "PRODUCT_TYPE") AS
  SELECT distinct
  mia.ACCOUNT_NO,
    mia.INSTRUMENT_ID as INSTRUMENT_ID,
    mii.INSTUMENT_ID,
    mii.SYMBOL,
    i.INSTRUMENT_SYMBOL,
   i.PRODUCT_TYPE

FROM
  MAP_INST_ACCNT mia,
         MAP_INST_UNL mii,
   UNDERLYING_INST i
          where mia.INSTRUMENT_ID = mii.INSTRUMENT_ID
   and  mii.INSTUMENT_ID = i.INSTRUMENT_ID;


Code:
<hibernate-mapping>
    <class name="pojo.Instruments" table="INSTRUMENTS" >
        <composite-id name="id" class="pojo.InstrumentsId">
            <key-property name="accountNo" type="string">
                <column name="ACCOUNT_NO" />
            </key-property>
            <key-property name="InstrumentId" type="string">
                <column name="INSTRUMENT_ID" />
            </key-property>
            <key-property name="instumentId" type="string">
                <column name="INSTUMENT_ID" />
            </key-property>
            <key-property name="Symbol" type="string">
                <column name="SYMBOL" />
            </key-property>
            <key-property name="instrumentSymbol" type="string">
                <column name="INSTRUMENT_SYMBOL" />
            </key-property>
            <key-property name="productType" type="string">
                <column name="PRODUCT_TYPE" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>


Code:
package pojo;

public class InstrumentsId implements java.io.Serializable {

   private String accountNo;
   private String InstrumentId;
   private String instumentId;
   private String Symbol;
   private String instrumentSymbol;
   private String productType;

   public InstrumentsId() {
   }

   public InstrumentsId(String accountNo, String InstrumentId) {
      this.accountNo = accountNo;
      this.InstrumentId = InstrumentId;
   }

   public InstrumentsId(String accountNo, String InstrumentId,
         String instumentId, String Symbol, String instrumentSymbol,
         String productType) {
      this.accountNo = accountNo;
      this.InstrumentId = InstrumentId;
      this.instumentId = instumentId;
      this.Symbol = Symbol;
      this.instrumentSymbol = instrumentSymbol;
      this.productType = productType;
   }

   public String getAccountNo() {
      return this.accountNo;
   }

   public void setAccountNo(String accountNo) {
      this.accountNo = accountNo;
   }

   public String getInstrumentId() {
      return this.InstrumentId;
   }

   public void setInstrumentId(String InstrumentId) {
      this.InstrumentId = InstrumentId;
   }

   public String getInstumentId() {
      return this.instumentId;
   }

   public void setInstumentId(String instumentId) {
      this.instumentId = instumentId;
   }

   public String getSymbol() {
      return this.Symbol;
   }

   public void setSymbol(String Symbol) {
      this.Symbol = Symbol;
   }

   public String getInstrumentSymbol() {
      return this.instrumentSymbol;
   }

   public void setInstrumentSymbol(String instrumentSymbol) {
      this.instrumentSymbol = instrumentSymbol;
   }

   public String getProductType() {
      return productType;
   }

   public void setProductType(String productType) {
      this.productType = productType;
   }

   public boolean equals(Object other) {
      << Auto Generated Code 4m Hibernate Reverse Engineering>
   }

   public int hashCode() {
            << Auto Generated Code 4m Hibernate Reverse Engineering>
         }

Code:
package pojo;


public class Instruments implements java.io.Serializable {

   private InstrumentsId id;

   public Instruments() {
   }

   public Instruments(InstrumentsId id) {
      this.id = id;
   }

   public InstrumentsId getId() {
      return this.id;
   }

   public void setId(InstrumentsId id) {
      this.id = id;
   }
   
   @Override
   public String toString()
   {
      /*
       * Need to be combination of AccountNumber-AccountName
       */
      String instrumentDisplay = id.getInstrumentSymbol();
      return instrumentDisplay;
   }

}

Code:
public class InstrumentDAOImpl extends HibernateDaoSupport implements InstrumentDAO
{

@Override
   public List<Instruments> getAllInstrumentSymbols() {
         DetachedCriteria criteria = DetachedCriteria.forClass(Instruments.class);
           List<Instruments> instList = getHibernateTemplate().findByCriteria(criteria);
           return instList;
   }
}


Top
 Profile  
 
 Post subject: Re: N Select Queries fired for 1 call( N = no of rows in view)
PostPosted: Thu Feb 18, 2010 1:00 am 
Newbie

Joined: Tue Feb 16, 2010 11:31 am
Posts: 2
Any clues about it guys ??


Top
 Profile  
 
 Post subject: Re: N Select Queries fired for 1 call( N = no of rows in view)
PostPosted: Thu Feb 18, 2010 3:20 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Why do you use DetachedCriteria and not Criteria itself?


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