-->
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: many-to-one mit formula oder where
PostPosted: Mon May 14, 2007 6:37 am 
Newbie

Joined: Wed Apr 25, 2007 4:30 am
Posts: 3
Ich hab folgendes Mapping

Code:
<class name="Statistic" table="statistic">
    <id name="id" column="statistic_id">
      <generator class="native"/>
    </id>

    <many-to-one name="hash" class="StatisticHash" property-ref="statisticId" cascade="save-update,delete">
      <formula>( select sh.* from statistic_hash sh where sh.statistic_row = 0 and sh.statistic_id = statistic_id )</formula>
   </many-to-one>
</class>

<class name="StatisticHash" table="statistic_hash">
    <id name="id" column="id">
      <generator class="native"/>
    </id>

    ...
</class>


Das Problem ist, dass in die Tabelle statistic_hash mehrere Zeilen mit der statistic_id existieren und ich somit bei der Beziehung nur die Zeilen berücksichtigen möchte, die als statistic_row = 0 haben. Dann existiert nur eine gültige Zeile.
Das dachte ich könnte man mit so einem Formula-Tag lösen, aber das Mapping wie oben beschrieben liefert den folgenden Fehler:
Nur ein einziger Ausdruck kann in der Auswahlliste angegeben werden, wenn die Unterabfrage nicht mit EXISTS eingeleitet wird.

Hibernate generiert folgendes falsche SQL:
Code:
select singlestat0_.statistic_id as statistic1_3_, singlestat0_.date_create as date3_3_, singlestat0_.field_info as field4_3_, singlestat0_.field_text as field5_3_, singlestat0_.flag as flag3_, singlestat0_.order_id as order7_3_, singlestat0_.input_id as input8_3_, singlestat0_.charge_id as charge9_3_, singlestat0_.fk_machine_id as fk10_3_, [b]( select sh.* from statistic_hash sh where sh.statistic_row = 0 and sh.statistic_id = singlestat0_.statistic_id )[/b] as formula0_ from statistic singlestat0_ where singlestat0_.statistic_class='2'



Wie schränke ich diese many-to-one Beziehung richtig ein?

Grüße
jack-flash


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.