MoienGK
MoienGK

Reputation: 4654

HQL NamedQuery with inner join on a HashMap

I am developing a JSF project and using Hibernate over mysql

as you may know (it is in the Hibernate documentation), joins use associations between entities. So a sample correct query with an inner join will be :

select from Person p join p.classes c where c.room = :roomNum

bu in my case the associated entity is a HashMap which contains the desired entity. some code will help :

public FamilyGuy{

private String name;
private BigDecimal income;
private HashMap<String, Child> children = new HashMap<Language, Child>();
....
} 

public Child{
private String name;
private BigDecimal expenses;
....
}

what i need is a query like this (the below query is not working) :

select from FamilyGuy oppressed inner join Child happy where happy.expenses < :threshold

the exception i am getting is :

javax.servlet.ServletException: Path expected for join!

any help will be appreciated.

Upvotes: 0

Views: 1279

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

select f from FamilyGuy f 
inner join f.children child
where child.expenses < :threshold

just like with any other toMany association.

As you said; joins use associations. So you can't specify the name of an entity (join Child), but must specify an association: join f.children... just like in the example at the start of your question.

Upvotes: 1

Related Questions