Volodymyr Kozubal
Volodymyr Kozubal

Reputation: 1400

Criteria API root.join operation. What happen?

I have an entity Provider and each provider has list of ProviderLanguage

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = PROVIDER_ID, referencedColumnName = PROVIDER_ID)
private Set<ProviderLanguage> providerLanguages;

A part of providers don't have a languages. When i write this code line

Join<Provider, Language> prLanJoin = root.join(Provider.PROVIDER_LANGUAGES)
                .join(Language.LANGUAGE);

simply unused prLanJoin variable, my search result doesn't include froviders that doesn't have languages. But how this line of code effect search result though prLanJoin doesn't used anywhere.

When i comment this line it works as expected, at least for me)

P.S I do not use prLanJoin join in code any more. I can simply comment this line and code will work.

Thanks.

Upvotes: 0

Views: 131

Answers (1)

nsthethunderbolt
nsthethunderbolt

Reputation: 2095

Too strange at first, after googling I found and here is the answer...

Acc to specification: Joins can be chained together to navigate to related entities of the target entity without having to create a Join instance for each join.

So even if you are not using the instance, the join method has operated on..may be using the Metamodels

The target of the join uses the Metamodel class of type EntityType to specify the persistent field or property of the joined entity.

Upvotes: 1

Related Questions