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.  [ 1 post ] 
Author Message
 Post subject: Write hql request
PostPosted: Fri Nov 06, 2009 10:40 am 
Newbie

Joined: Tue Mar 31, 2009 5:55 am
Posts: 4
Hi,

Ihave a bug when send the sql request to nhibernate with the :
IQuery q = m_session.CreateSQLQuery(request);
result = q.SetTimeout(3600).List();
The bug is that I want to see the c.Dv field et the c.Dn values but I see 2 times the same value of the field c.Dv in the result list .
The two fields are decimal(18,3).

I would write the sql query in Hql. Can Someones can help me please ?

Code:
SELECT o.OutletId, o.Name, (SELECT DISTINCT c.Dv From CoeficientProd c WHERE c.OutletId = o.OutletId AND c.DayId=20091105),
(SELECT DISTINCT c.Dn From CoeficientProd c WHERE c.OutletId = o.OutletId AND c.DayId=20091105) From Outlet o, OutletSubChannel osc
WHERE o.OutletId=osc.OutletId AND osc.SubChannelId IN (9,236,5,233,6,234,2,1,10,8,237,7,4,238,239,0,235,3,11)
ORDER BY o.OutletId


Theses are my nhibernate classes :

Code:
public class Outlet
    {
        private int m_Id;
        private String m_Name;
        private String m_Code;
        private Boolean m_IsDummy;
        private OutletGroup m_OutletGroup;
        private IList<SubChannel> m_SubChannels;
        private IList<Bkz> m_BKZs;
        private String m_adress;
        private String m_postalCode;
        private String m_country;
        private Department m_Department;
        private int m_Size;
  }

public class SubChannel
    {
        private int m_Id;
        private String m_Name;
        private Channel m_Channel;
        private IList<Outlet> m_Outlets;
    }

public class CoeficientProd
    {
        private int m_Id;
        private Outlet m_Outlet;
        private Day m_Day;
        private LoadProcess m_LoadProcess;
        private Double m_DN;
        private Double m_DV;
        private String m_TypeDndv;
   }


and my hbm

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
 
  <class name="CoeficientProd" table="CoeficientProd">
    <!--<cache usage="read-write"/>-->
    <id name="Id" column="CoeficientId" unsaved-value="0">
      <generator class="native"/>
    </id>
   
    <many-to-one name="Outlet" column="OutletId" not-null="false"/>
   <many-to-one name="Day" column="DayId" not-null="false"/>

    <many-to-one name="LoadProcess" column="LoadProcessId" not-null="false"/>

     <!--<property name="DN" column="DN" type="decimal(18,3)" not-null="false"/>
     <property name="DV" column="DV" type="decimal(18,3)" not-null="false"/>-->

    <property name="DN" column="DN"  not-null="false"/>
    <property name="DV" column="DV"  not-null="false"/>

    <property name="TypeDndv" column="TypeDndv" not-null="false"/>

    <property name="LastModified" column="lastModified"  not-null="false" />
    <property name="LastModifiedBy" column="lastModifiedBy" not-null="false" />
    <property name="CreateDate" column="createDate" not-null="false" />
    <property name="CreatedBy" column="createdBy" not-null="false" />
  </class>
 
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <class name="Outlet" table="Outlet">
    <id name="Id" column="OutletId" unsaved-value="0">
      <generator class="native"/>
    </id>

    <property name="Name" column="Name" not-null="false"/>
    <property name="Code" column="Code" not-null="false" length="6"/>
    <property name="IsDummy" column="IsDummy" not-null="false"/>

    <bag
       name="BKZs"
       inverse="true"
       lazy="true"
       cascade="save-update">
      <key column="OutletId"/>
      <one-to-many class="GFK.CEB.Business.Bkz"/>
    </bag>

    <property name="Adress" column="Adress" not-null="false"/>
    <property name="PostalCode" column="PostalCode" not-null="false"/>
    <property name="Country" column="Country" not-null="false"/>

    <many-to-one name="OutletGroup" column="OutletGroupId" not-null="false"/>
    <many-to-one name="Department" column="DepartmentId" not-null="false" />

    <bag name="SubChannels" table="OutletSubChannel" inverse="true" lazy="true"
     cascade="save-update">
      <key column="OutletId"/>
      <many-to-many column="SubChannelId"
           class="SubChannel"/>
    </bag>

    <property name="Size" column="Size" not-null="false"/>

    <property name="LastModified" column="lastModified"  not-null="false" />
    <property name="LastModifiedBy" column="lastModifiedBy" not-null="false" />
    <property name="CreateDate" column="createDate" not-null="false" />
    <property name="CreatedBy" column="createdBy" not-null="false" />
  </class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
 
  <class name="SubChannel" table="SubChannel">
    <id name="Id" column="SubChannelId" unsaved-value="0">
      <generator class="native"/>
    </id>
   
    <property name="Name" column="Name" not-null="false"/>
    <many-to-one name="Channel" column="ChannelId" not-null="false"/>

    <bag name="Outlets" table="OutletSubChannel" cascade="none" lazy="true" >
      <key column="SubChannelId"/>
      <many-to-many column="OutletId"
           class="Outlet"/>
    </bag>
    <property name="LastModified" column="lastModified"  not-null="false" />
    <property name="LastModifiedBy" column="lastModifiedBy" not-null="false" />
    <property name="CreateDate" column="createDate" not-null="false" />
    <property name="CreatedBy" column="createdBy" not-null="false" />
  </class>
</hibernate-mapping>


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

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.