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!!!