-->
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: Problem with key-many-to-one : bug ?
PostPosted: Tue Oct 21, 2003 6:04 am 
Expert
Expert

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

My mappings are
Code:
<class name="Foo" table="FOO">

  <id name="id">

    <generator class="increment" />

  </id>

  <property name="text"/>

</class>

<class name="Bar" table="BAR">

  <composite-id>

    <key-many-to-one name="foo" class="Foo">

      <column name="ID_FOO" />

    </key-many-to-one>

  </composite-id>   


  <property name="text"/>

</class>



I have the java classes that corresponds to these mappings.
I want to retrieve one Bar object so I have this code :

Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();



Criteria criteria = session.createCriteria(Foo.class);

criteria.add(Expression.eq("id", new Integer(1)));

Foo foo = (Foo) criteria.uniqueResult();

System.out.println("Foo :" + foo.getId());



criteria = session.createCriteria(Bar.class);

criteria.createCriteria("foo").add(Expression.eq("id", new Integer(1)));

Bar bar = (Bar) criteria.uniqueResult();

System.out.println("Bar :" + bar.getFoo().getId());



session.close();



Hibernate generates the sql code below :
Code:
select this.ID_FOO as ID_FOO0_, this.text as text0_ from BAR this where x0_.id=1

and I have an sql error.

With an HQL query like "from Bar bar where bar.foo.id=1" it works great.

So, it seems that there is a bug in the criteria API, isn't it ?

Seb


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.