-->
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: Trouble with bidirectional one to one and setEntity
PostPosted: Tue Oct 17, 2006 4:04 pm 
Newbie

Joined: Tue Oct 17, 2006 3:48 pm
Posts: 1
Hi folks,

I face a strange result when using setEntity in my queries when using bidirectional one to one association.

I have reduced my probleme to the follow testcase :

A [1]< -----------> [0..1] B

Mapping file :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="debug">

<class name="A">
    <id name="id" column="a_id">
        <generator class="native"/>
    </id>
   <property   name="name"
            type="string"
            not-null="true"/>   
    <many-to-one name="b"
        column="b_id"
        unique="true"
        not-null="false"/>
</class>

<class name="B">
    <id name="id" column="b_id">
        <generator class="native"/>
    </id>
   <property   name="name"
            type="string"
            not-null="true"/>       
   <one-to-one name="a"
        property-ref="b"/>
</class>

</hibernate-mapping>


(name attribute just to be clearer)

My test data :

Code:
dbtest=# select * from a;
a_id | name | b_id
------+------+------
    3 | a3   |
    1 | a1   |    5
    2 | a2   |    6
(3 lignes)

dbtest=# select * from b;
b_id | name
------+------
    4 | b1
    5 | b2
    6 | b3
(3 lignes)

dbtest=#


Particularly, I have a2 <---------> b3

Trouble is, I am able to get A from B using :
Code:
List result = session.createQuery("from A a where a.b = ?").setEntity(0, b3).list();


I get a list containing a2.

But the other direction does not work :
Code:
List result = session.createQuery("from B b where b.a = ?").setEntity(0, a2).list();

(empty list returned instead of a list containing b3)

But this seems to be related to setEntity as other queries are working as expexted :
Code:
List result = session.createQuery("from B b where b.a.name = ?").setParameter(0, "a2").list();
List result = session.createQuery("from B b inner join fetch b.a where b.a.id = ?").setParameter(0, a2.getId()).list();


Am I doing something wrong ?

Many thanks...

Quentin


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.