Thinking in doing this in a different way, I try to create a HQL query through
@NamedQuery.
The "target" list to search in, is in the
Publication entity (related to last post, now I'm trying with
java.util.Set (non-ordered collection)):
Code:
@OrderBy("writerOrder")
@OneToMany(mappedBy="publicationWriterPK.publication", targetEntity=PublicationWriter.class)
protected Set<Researcher> researcherList = new HashSet<Researcher>();
In
Book entity, the declared query seems like this :
Code:
@NamedQuery(name="BooksFromResearcher", query="FROM Book " +
" WHERE :researcherList IN researcherList " +
" ORDER BY year")
And in the corresponding DAO:
Code:
@SuppressWarnings("unchecked")
public List<Book> getPublicationsByResearcher(Researcher researcher)
{
Set<Researcher> researcherList = new HashSet<Researcher>();
researcherList.add(researcher);
return (List<Book>) getHibernateTemplate().findByNamedQueryAndNamedParam("BooksFromResearcher", "researcherList", researcherList);
}
Launching this query, the result is :
Code:
Hibernate:
select
book0_.book_key as pub1_27_,
book0_1_.pub_isbn as pub2_27_,
book0_1_.pub_book as pub3_27_,
book0_1_.pub_edit as pub4_27_,
book0_1_.pub_file as pub5_27_,
book0_1_.pub_link as pub6_27_,
book0_1_.pub_loc as pub7_27_,
book0_1_.pub_prsnt as pub8_27_,
book0_1_.pub_subj as pub11_27_,
book0_1_.pub_title as pub9_27_,
book0_1_.pub_year as pub10_27_,
book0_.book_edit as book2_29_,
book0_.book_pages as book3_29_,
book0_.book_sub_tit as book4_29_,
book0_.book_vol as book5_29_
from
book book0_
inner join
publication book0_1_
on book0_.book_key=book0_1_.pub_key,
publication_writer researcher1_
where
book0_.book_key=researcher1_.pub_key
and (
? in (
{non-qualified-property-ref}
)
)
order by
book0_1_.pub_year
If I try to change the query to:
Code:
@NamedQuery(name="BooksFromResearcher", query="FROM Book AS b " +
" WHERE :researcherList IN b.researcherList " +
" ORDER BY b.year")
the resulted query is :
Code:
Hibernate:
select
book0_.book_key as pub1_27_,
book0_1_.pub_isbn as pub2_27_,
book0_1_.pub_book as pub3_27_,
book0_1_.pub_edit as pub4_27_,
book0_1_.pub_file as pub5_27_,
book0_1_.pub_link as pub6_27_,
book0_1_.pub_loc as pub7_27_,
book0_1_.pub_prsnt as pub8_27_,
book0_1_.pub_subj as pub11_27_,
book0_1_.pub_title as pub9_27_,
book0_1_.pub_year as pub10_27_,
book0_.book_edit as book2_29_,
book0_.book_pages as book3_29_,
book0_.book_sub_tit as book4_29_,
book0_.book_vol as book5_29_
from
book book0_
inner join
publication book0_1_
on book0_.book_key=book0_1_.pub_key,
publication_writer researcher1_
where
book0_.book_key=researcher1_.pub_key
and (
? in (
.
)
)
order by
book0_1_.pub_year
I don't know if this is the correct way to solve my problem, but I'm still waiting for the response to the last post (and now for the reply to this, jeje).
A lot of thanks