-->
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.  [ 2 posts ] 
Author Message
 Post subject: Domain obj mapped with derived property - load w/custom sql?
PostPosted: Fri Aug 17, 2007 10:39 am 
Newbie

Joined: Thu Aug 16, 2007 1:24 pm
Posts: 4
Hibernate version: 3.2.4.sp1
Name and version of the database you are using: Oracle 10

I have a ContractTier object loaded normally by hibernate via the following mapping:

Code:
<hibernate-mapping>
    <class name="ContractTier" table="NPC_CONTRACT_TIER">
        <id name="contractTierId" type="long">
            <column name="CONTRACT_TIER_ID" precision="18" scale="0" />
            <generator class="sequence" ><param name="sequence">NPC_CONTRACT_TIER_SEQ</param></generator>
        </id>
        <many-to-one name="npcContract" class="Contract" fetch="select">
            <column name="NPC_CONTRACT_ID" precision="18" scale="0" not-null="true" />
        </many-to-one>
        <property name="description" type="string">
            <column name="DESCRIPTION" length="50" />
        </property>

    </class>
</hibernate-mapping>


I have a ContractDifference domain object which contains a collection of these ContractTier objects. I load the ContractDifference object with a custom sql query. Here is the mapping for ContractDifference:
Code:
<hibernate-mapping>
    <class name="ContractDifference" mutable="false">
       <id name="id" />
       <property name="customerContractId" not-null="true" update="false" insert="false" />
       <property name="memberName" not-null="true" update="false" insert="false" />
       <property name="supplierName" not-null="true" update="false" insert="false" />

       <set name="tierAdditions" inverse="true">
          <key column="npc_contract_id" />
          <one-to-many class="ContractTier"/>
          <loader query-ref="getContractTierAdditions"/>
       </set>
       
      <loader query-ref="getContractDifferences"/>       
    </class>
   
    <sql-query name="getContractDifferences">
       <return alias="cd" class="ContractDifference" />
      <![CDATA[SELECT npc.npc_contract_id as {cd.id},
                  npc.customer_contract_id as {cd.customerContractId},
                  mbr.member_name as {cd.memberName},
                  sca.member_name as {cd.supplierName}
                      FROM npc_contract npc
                      JOIN ec_master_contract_header sca
                        ON npc.contract_id = sca.contract_id
                       AND npc.supplier_member_id = sca.member_id
                       AND sca.community = 'mycommunity'
                       AND sca.revision_id = 1
                      JOIN ec_master_member mbr
                        ON npc.member_id = mbr.member_id
                      WHERE npc.npc_contract_id=:id]]>      
   </sql-query>

      <sql-query name="getContractTierAdditions">
         <load-collection  alias="tier" role="ContractDifference.tierAdditions" />
         <![CDATA[SELECT tier.contract_tier_id,
                     tier.npc_contract_id,
                     tier.description
                FROM npc_contract_tier tier
                JOIN npc_contract npc
                  ON npc.npc_contract_id = tier.npc_contract_id
                LEFT OUTER JOIN ec_master_contract_detail dtl
                       ON dtl.community = 'mycommunity'
                      AND dtl.member_id = npc.supplier_member_id
                      AND dtl.contract_id = npc.contract_id
                      AND dtl.revision_id = 1
                      AND dtl.description = tier.description
                WHERE
                   npc.npc_contract_id = :id AND
                   dtl.description is null]]>
      </sql-query>

   
</hibernate-mapping>


All of the above works fine.
My issue arises once I add a derived property to the ContractTier object as so:

Code:
<hibernate-mapping>
    <class name="ContractTier" table="NPC_CONTRACT_TIER">
        <id name="contractTierId" type="long">
            <column name="CONTRACT_TIER_ID" precision="18" scale="0" />
            <generator class="sequence" ><param name="sequence">NPC_CONTRACT_TIER_SEQ</param></generator>
        </id>
        <many-to-one name="npcContract" class="Contract" fetch="select">
            <column name="NPC_CONTRACT_ID" precision="18" scale="0" not-null="true" />
        </many-to-one>
        <property name="description" type="string">
            <column name="DESCRIPTION" length="50" />
        </property>

        <property name="itemCount"
            type="int"
            formula="(select count(*) from npc_price_list p where p.Contract_Tier_id = CONTRACT_TIER_ID )"
         />

    </class>
</hibernate-mapping>


Is it possible to modify the sql query getContractTierAdditions to add the itemCount property for ContractTier objects? Maybe I'm battling something that is not possible.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 4:02 pm 
Newbie

Joined: Thu Aug 16, 2007 1:24 pm
Posts: 4
This appears to be a known bug:
http://opensource.atlassian.com/project ... -um7JJmw1r


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