2012-05-31 4 views
0

단일 테이블을 쿼리하기 위해 springframework HibernateTemplate을 사용하고 있습니다. 디버그 설정을 사용하여 Hibernate가 생성하는 쿼리를 캡처하여 Toad에서 실행하고 75 개의 별개의 행을 확보했습니다. 그러나 내 응용 프로그램에서는 75 개의 중복 레코드가있는 컬렉션을 얻습니다.springframework/hibernate가 중복 행을 반환합니다.

<hibernate-mapping> 
<class name="com.p.e.d.s.PmaSummary" <!-- hiding info --> 
    table="V_PMA_SUMMARY" schema="ECREDIT"> 

    <cache usage="read-only" /> 

    <id column="member_id" name="memberId"> 
     <generator class="assigned" /> 
    </id> 

    <property name="weekEnding" column="week_ending" /> 
    <property name="actualInvoice" column="actual_invoice" /> 
    <property name="ftrAdjustments" column="ftr_adjustments" /> 
    <property name="edcLseAdjustments" column="edc_lse_adjustments" /> 
    <property name="blidAdjustments" column="blid_adjustments" /> 
    <property name="pmaMiscAdjustments" column="pma_misc_adjustments" /> 
    <property name="pmaEarlyPayments" column="pma_early_payments" /> 
    <property name="adjInv" column="adj_inv" /> 
    <property name="adjInvExcEarlyPayment" column="adj_inv_exc_early_payment" /> 
    <property name="initialPma" column="initial_pma" /> 
    <property name="threeWeekPma" column="three_week_pma" /> 
    <property name="pmaOverride" column="pma_override" /> 
    <property name="pmaOverride_type" column="pma_override_type" /> 
    <property name="pmaOverride_reason" column="pma_override_reason" /> 
</class> 
</hibernate-mapping> 

을 그리고 이것은 쿼리가 두꺼비에서 제대로 작동 생성 :

select this_.member_id as member1_45_0_, 
    this_.week_ending as week2_45_0_, 
    this_.actual_invoice as actual3_45_0_, 
    this_.ftr_adjustments as ftr4_45_0_, 
    this_.edc_lse_adjustments as edc5_45_0_, 
    this_.blid_adjustments as blid6_45_0_, 
    this_.pma_misc_adjustments as pma7_45_0_, 
    this_.pma_early_payments as pma8_45_0_, 
    this_.adj_inv as adj9_45_0_, 
    this_.adj_inv_exc_early_payment as adj10_45_0_, 
    this_.initial_pma as initial11_45_0_, 
    this_.three_week_pma as three12_45_0_, 
    this_.pma_override as pma13_45_0_, 
    this_.pma_override_type as pma14_45_0_, 
    this_.pma_override_reason as pma15_45_0_ 
from ecredit.v_pma_summary this_ 
where this_.member_id = 10003 
order by this_.week_ending desc; 
+0

이 테이블에는 복합 키가 있습니다. 복합 키의 단일 속성에서 두 속성으로 변경하면 문제가 해결되었습니다. –

답변

1

왜 당신의 HQL 쿼리에 DISTINCT 추가가수록

매핑은 간단하다?

0

매핑 파일의 id 정의가 올바르지 않습니다. <ìd>을 사용하면 단일 열을 기본 키로 정의 할 수 있습니다.

하나의 member_id에 대해 모든 행을 선택하고 week_ending까지 주문하십시오. 그래서 같은 member_id에 대해 week_ending이 다른 많은 열이있을 수 있습니다. 따라서 기본 키에는 member_id 및 week_ending과 sth 등 두 개 이상의 열이있을 수 있습니다. 그밖에.

<composite-id> 대신 <id>, sth를 사용해야합니다. like this

<composite-id> 
    <key-property name="memberId" column="member_id" type="..." /> 
    <key-property name="weekEnding" column="week_ending" type="..." /> 
    <!--- perhaps more key-properties --> 
</composite-id> 
관련 문제