-->
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.  [ 3 posts ] 
Author Message
 Post subject: Where attributes do not work in sets
PostPosted: Thu Jul 22, 2004 5:05 am 
Newbie

Joined: Fri Nov 21, 2003 2:20 am
Posts: 5
Hello,

It seems that where attribute does not work in the sets in some situations. I am using Hibernate 2.1.4 and the database is Oracle9.

This is a clip of a mapping with two quite similar sets:


Code:
<class name="Instance" table="instances">

<composite-id name="id" class="InstanceId">
      <key-property name="familyId" type="string" column="instance_family_id"/>
      <key-property name="version" type="integer" column="version"/>
</composite-id>

<set name="primaryComponentRelations" lazy="false" inverse="false" where="is_primary = 1" table="components_instances">
       <key>
          <column name="instance_family_id"/>
          <column name="version"/>
        </key>
        <one-to-many class="ComponentInstanceRelation"/>
</set>

<set name="alternativeComponentRelations" lazy="false"
        inverse="false" where="is_primary = 0" table="components_instances">
        <key>
          <column name="instance_family_id"/>
          <column name="version"/>
        </key>
        <one-to-many class="ComponentInstanceRelation"/>
</set>

</class>


As you can see there is two sets, with the difference that boolean field is_primary has different value.

Here is the mapping of the ComponentInstanceRelation:

Code:
<class name="ComponentInstanceRelation" lazy="true" table="components_instances">

    <composite-id name="id">
      <key-property name="caseId" type="string" column="vcase_id"/>
      <key-property name="index" type="integer" column="comp_index"/>
      <key-property name="instanceFamilyId" type="string" column="instance_family_id"/>
      <key-property name="version" column="version" type="integer"/>
    </composite-id>
   
    <property name="name" type="string" column="name"/>
    <property name="primary" column="is_primary" type="boolean" not-null="true"/>
    <property name="componentName" column="component_name"/>
    <property name="labelName" not-null="true" column="label_name"/>
   
    <many-to-one name="instance" class="Instance" insert="false" update="false">
       <column name="instance_family_id"/>
       <column name="version"/>
    </many-to-one>

    <many-to-one name="component" class="Component" insert="false" update="false">
       <column name="vcase_id"/>
       <column name="comp_index"/>
    </many-to-one>

  </class>


ComponentInstanceRelation is just a middle table, but I implemented it as a normal mapping, because it has to do some complicated operations and I could not get them working when it was mapped as composite-element. Such as, when a new version of the Instance is created, relation must be changed to it from the old instance. This means that at database level relation must be deleted and a new must be created with different instance.

The new implementation seems to work, but the problem is that both getPrimaryComponentRelations() and getAlternativeComponentRelations() in the Instance give the same set of ComponentInstanceRelation objects as result. When checked from database there is an instance with 166 primary relations (is_primary=1) and 0 alternative relations(is_primary=0). However when using Hibernate, both sets contain all 166 relations.

So my question is, is there a bug in Hibernate and if not, what am I doing wrong, and if there is a bug, how do I get around it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 7:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
try to lazy both sets
Then when calling getPrimaryComponentRelations--> check sql generated
do the same for getAlternativeComponentRelations

copy paste the sql into a db client and check what it is returning

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 12:45 am 
Newbie

Joined: Fri Nov 21, 2003 2:20 am
Posts: 5
Unfortunately, I already gave up this technique on the matter. So I can not test the sql anymore. Maybe I will do it, if I have the time in the near future. Currently I am using direct jdbc (yuck). As a mysterious detail the same code worked correctly in a simple JUnit test, but failed in the JBoss application. The hibernate.cfg.xml was exactly the same for both. Beats me.


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