-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one bugs with hibernate 3.2.ga
PostPosted: Tue Oct 17, 2006 11:23 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi,

I have a one-to-one relationship with property-ref between Master and Slave2.
I want to find all Master instances that have a null Slave2 instance associated.
To do so my query is
Code:
select master from Master master where master.slave2 is null

The sql generated is
Code:
select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_ where master0_.oid is null

which seems incorrect. It checks here Master instances with null id (config files are listed below).

If I do my query like this
Code:
select master from Master master where master.slave2.oid is null

the generated sql is ok :
Code:
select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_, Slave2 slave2x1_ where master0_.oid=slave2x1_.myMaster and (slave2x1_.oid is null)


Is this a bug ?

The log below also contains a test case related to a bug I have submitted in JIRA in 3.2cr2 version (HHH-1849) and that is always here in 3.2.ga : can the two problems be related ?

Thanx for your help

Seb


Hibernate version:
3.2.ga
Mapping documents:
Master
Code:
<hibernate-mapping>
  <class name="Master">
    <id name="oid">
      <generator class="foreign">
        <param name="property">slave</param>
      </generator>
    </id>
    <property name="libelle" type="string" />
    <one-to-one name="slave" class="Slave" constrained="true" />
    <one-to-one name="slave2" class="Slave2" property-ref="myMaster" />
  </class>
</hibernate-mapping>

Slave
Code:
<hibernate-mapping>
  <class name="Slave">
    <id name="oid">
      <generator class="native" />
    </id>
    <property name="libelle" type="string" />
  </class>
</hibernate-mapping>

Slave2
Code:
<hibernate-mapping>
  <class name="Slave2">
    <id name="oid">
      <generator class="native" />
    </id>
    <property name="libelle" type="string" />
    <many-to-one name="myMaster" class="Master" />
  </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
        Transaction tx = session.beginTransaction();
        Slave slave = new Slave();
        slave.setOid(1);
        session.save(slave);
        Master master = new Master();
        master.setSlave(slave);
        session.save(master);
        Query query;
        query = session.createQuery("select master from Master master where master.slave2 is null");
        System.out.println("Requete avec is null");
        for (Object object : query.list())
        {
            System.out.println(object);
        }
        query = session.createQuery("select master from Master master where master.slave2.oid is null");
        System.out.println("Requete avec is null sur oid");
        for (Object object : query.list())
        {
            System.out.println(object);
        }
        query = session.createQuery("from Master master where master.slave.oid=:oid");
        query.setParameter("oid", 1);
        System.out.println("Requete sur l'oid");
        for (Object object : query.list())
        {
            System.out.println(object);
        }
        query = session.createQuery("from Master master where master.slave=:slave");
        query.setParameter("slave", slave);
        System.out.println("Requete sur l'objet");
        for (Object object : query.list())
        {
            System.out.println(object);
        }
        tx.commit();

Full stack trace of any exception that occurs:
Log
Code:
Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE
Requete avec is null
Hibernate: insert into Slave (libelle, oid) values (?, ?)
Hibernate: insert into Master (libelle, oid) values (?, ?)
Hibernate: select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_ where master0_.oid is null
Requete avec is null sur oid
Hibernate: select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_, Slave2 slave2x1_ where master0_.oid=slave2x1_.myMaster and (slave2x1_.oid is null)
Requete sur l'oid
Hibernate: select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_ where master0_.oid=?
Master@121177e
Requete sur l'objet
Hibernate: select master0_.oid as oid0_, master0_.libelle as libelle0_ from Master master0_ where master0_.oid=?
2006-10-17 16:15:47,756 ERROR : Not all parameters were set.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:2147)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
   at org.hibernate.loader.Loader.list(Loader.java:2023)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at Test.main(Test.java:47)
Caused by: org.firebirdsql.jdbc.FBMissingParameterException: Not all parameters were set.
   at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:481)
   at org.firebirdsql.jdbc.AbstractPreparedStatement.executeQuery(AbstractPreparedStatement.java:109)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2144)
   ... 8 more

Name and version of the database you are using:
Firebird 1.5.3 with jaybird

The generated SQL (show_sql=true):
In the log

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 3:07 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I have submitted a JIRA issue for that : http://opensource.atlassian.com/project ... e/HHH-2158

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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