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;
}
}