-->
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: Multi-criteria problem
PostPosted: Sat Jun 09, 2007 1:36 pm 
Newbie

Joined: Sat Jun 09, 2007 1:13 pm
Posts: 2
Hi All!

I have following model: Keyword >--< Book >--< Author

This is my hbms:

Code:
<hibernate-mapping package="org.dlisin.ebc.catalog.model.impl">
   <class name="BookImpl" table="Book">
      <id name="bookID" column="BookID">
         <generator class="assigned"/>
      </id>

      <property name="title" column="Title"/>

      <set name="authors" table="Author2Book" lazy="false" fetch="join">
         <key column="BookID"/>
         <many-to-many class="AuthorImpl" column="AuthorID"/>
      </set>
      <set name="keywords" table="Keyword2Book" lazy="false" fetch="join">
         <key column="BookID"/>
         <many-to-many class="KeywordImpl" column="KeywordID"/>
      </set>
   </class>
</hibernate-mapping>

<hibernate-mapping package="org.dlisin.ebc.catalog.model.impl">
   <class name="AuthorImpl" table="Author">
      <id name="authorID" column="AuthorID">
         <generator class="assigned"/>
      </id>

      <property name="firstName" column="FirstName"/>
      <property name="lastName" column="LastName"/>
   </class>
</hibernate-mapping>

<hibernate-mapping package="org.dlisin.ebc.catalog.model.impl">
   <class name="KeywordImpl" table="KeyWord">
      <id name="keywordID" column="KeyWordID">
         <generator class="assigned"/>
      </id>

      <property name="label" column="Label"/>
   </class>
</hibernate-mapping>


When I execute following code:

Code:
Criteria criteria = session.createCriteria( BookImpl.class );
return criteria.list();


All looks like good. I have one big select with outer joins.
But when I trying to use multi-criteria ( createAlias or createCriteria ):

Code:
Criteria criteria = session.createCriteria( BookImpl.class );
criteria.createAlias( "authors", "author" );
criteria.add( Restrictions.ilike( "author.firstName", "Ted", MatchMode.ANYWHERE  );
return criteria.list();


Outer joins are broken.
In my logs a have a lot of single selects:

Hibernate: select this_.BookID as BookID0_2_, this_.Title as Title0_2_, authors3_.BookID as BookID4_, author1_.AuthorID as AuthorID4_, author1_.AuthorID as AuthorID3_0_, author1_.FirstName as FirstName3_0_, author1_.LastName as LastName3_0_, keywords5_.BookID as BookID4_, keywordimp6_.KeyWordID as KeywordID4_, keywordimp6_.KeyWordID as KeyWordID4_1_, keywordimp6_.Label as Label4_1_ from Book this_ inner join Author2Book authors3_ on this_.BookID=authors3_.BookID inner join Author author1_ on authors3_.AuthorID=author1_.AuthorID left outer join Keyword2Book keywords5_ on this_.BookID=keywords5_.BookID left outer join KeyWord keywordimp6_ on keywords5_.KeywordID=keywordimp6_.KeyWordID where lower(author1_.FirstName) like ?
Hibernate: select authors0_.BookID as BookID1_, authors0_.AuthorID as AuthorID1_, authorimpl1_.AuthorID as AuthorID3_0_, authorimpl1_.FirstName as FirstName3_0_, authorimpl1_.LastName as LastName3_0_ from Author2Book authors0_ left outer join Author authorimpl1_ on authors0_.AuthorID=authorimpl1_.AuthorID where authors0_.BookID=?
Hibernate: select authors0_.BookID as BookID1_, authors0_.AuthorID as AuthorID1_, authorimpl1_.AuthorID as AuthorID3_0_, authorimpl1_.FirstName as FirstName3_0_, authorimpl1_.LastName as LastName3_0_ from Author2Book authors0_ left outer join Author authorimpl1_ on authors0_.AuthorID=authorimpl1_.AuthorID where authors0_.BookID=?

First select looks like good, but I a bit confused bu next select ... :-()

Please HELP me!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 10, 2007 12:03 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Tried adding setFechMode("author", FetchMode.JOIN) before calling list() ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 5:02 am 
Newbie

Joined: Sat Jun 09, 2007 1:13 pm
Posts: 2
batmat wrote:
Tried adding setFechMode("author", FetchMode.JOIN) before calling list() ?


Yes, I tried this. It is doesnot help. Any idea?


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.