-->
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: Produit cartésien en autre avec jointure auto sur component
PostPosted: Tue Aug 02, 2005 11:11 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Voici ci-dessous une différence que j'ai noté entre hibernate 2 et hibernate 3.

J'ai une classe Person avec un component Address qui a un lien many-to-one vers une classe City. Avec Hibernate 2.1.8 si je fait la requête hql "from Person p where p.address.city.id is null" j'ai bien mon résultat car la jointure impicite p.address.city.id ne génère aucune jointure sql vu que l'id de la city est dans la table person.
Avec hibernate 3.0.5 la même requête hql me génère un produit cartésien entre person et city avec en plus une clause where city.id is null. Or le produit cartésien ne récupère pas les valeurs null (normal) et donc je ne retrouve pas les mêmes enregistrements qu'avec Hibernate 2.

S'agit t'il de quelque chose de normal ou d'un bug dans hibernate 3.

Merci Pour vous réponses

Seb

Hibernate version:
3.0.5

Mapping documents:
Person
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test">
  <class name="Person">
    <id name="id" type="long">
      <generator class="increment" />
    </id>
    <property name="name" />
    <component name="address" class="test.Address" >
      <property name="location"/>
      <many-to-one name="city" class="test.City" />
    </component>
  </class>
</hibernate-mapping>

City
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test">
  <class name="City">
    <id name="id" type="long">
      <generator class="increment" />
    </id>
    <property name="name" />
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Transaction tx = session.beginTransaction();
session.createQuery("from Person p where p.address.city.id is null").list();
tx.commit();


Name and version of the database you are using:
hsqldb 1.7.x

The generated SQL (show_sql=true):
Pour hibernate 2 : select person0_.id as id, person0_.name as name, person0_.location as location, person0_.city as city from Person person0_ where (person0_.city is null )
Pour hibernate 3 : select person0_.id as id, person0_.name as name0_, person0_.location as location0_, person0_.city as city0_ from Person person0_, City city1_ where person0_.city=city1_.id and (city1_.id is null)


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.