Hibernate criteria.setFetchMode(“”) not working

Refresh

November 2018

Views

5.7k time

4

I have a simple Criteria, like this:

    final Criteria players = session.createCriteria(Players.class).add(Restrictions.idEq(1));    
    final Criteria team = players.createCriteria("team","team").add(notDeleted());    

i need a player with ID=1 and the team is not deleted this is working OK but i need the Owner of the team and the address of the owner. strangely this is not working..

team.createCriteria("owner").setFetchMode("address",FetchMode.JOIN);

This is not working neither:

team.createCriteria("owner").setFetchMode("owner.address",FetchMode.JOIN);

here i have the owner but i dont have the address. but Address is not fetched. Why this is i have the owner i can have the Address??

But this is working.

team.setFetchMode("owner",FetchMode.JOIN).setFetchMode("owner.address",FetchMode.JOIN);

why this?

any help is hugely appreciate.

thanks a lot.
UPDATE

my model is simple.

a team has a lot a player 1-N relationship. a team has a owner. N-1 relationship. a owner has a address.

multiple Players->oneTeam->one-owner->oneAddress.

4 answers

0

Вы можете поместить выборку объектов в rootCriteria. Подобно:

team.setFetchMode("owner",FetchMode.JOIN).setFetchMode("owner.address",FetchMode.JOIN);
0

Вы можете поместить выборку объектов в rootCriteria. Подобно:

team.setFetchMode("owner",FetchMode.JOIN).setFetchMode("owner.address",FetchMode.JOIN);
0

Вы можете поместить выборку объектов в rootCriteria. Подобно:

team.setFetchMode("owner",FetchMode.JOIN).setFetchMode("owner.address",FetchMode.JOIN);
0

Вы можете поместить выборку объектов в rootCriteria. Подобно:

team.setFetchMode("owner",FetchMode.JOIN).setFetchMode("owner.address",FetchMode.JOIN);