0

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.

Tiny
  • 27,221
  • 105
  • 339
  • 599
Volodymyr Kozubal
  • 1,320
  • 1
  • 12
  • 16
  • what's this liquibase?? is it not in the sync... BTW using .join() eliminates the records which are not in the intersection. So Providers not having languages are not coming up. – nsthethunderbolt Jul 13 '14 at 15:00
  • yes I understand how join works. Join prLanJoin = root.join(Provider.PROVIDER_LANGUAGES) .join(Language.LANGUAGE); ParameterExpression languagesParam = getCriteriaBuilder() .parameter(Collection.class, NewProviderSearchCriteria.LANG_PARAM); predicates.add(prLanJoin.get(Language.LANGUAGE_NAME).in(languagesParam)); I do not write such code. Just join. – Volodymyr Kozubal Jul 13 '14 at 15:06
  • in other words this join does not take apart in any Predicate – Volodymyr Kozubal Jul 13 '14 at 15:08
  • when you are selecting your results you are using prLanJoin, don't you?? then it doesn't needs to be in the predicate. – nsthethunderbolt Jul 13 '14 at 15:09
  • if it were to be in the predicate, then it would not have been a join as per JPA. – nsthethunderbolt Jul 13 '14 at 15:09
  • no i do not use it at all. I can simply comment this line. – Volodymyr Kozubal Jul 13 '14 at 15:10
  • so you have "root" which is not defined. Ok. perhaps provide a complete question – Neil Stockton Jul 13 '14 at 15:47

1 Answers1

1

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.

nsthethunderbolt
  • 2,059
  • 1
  • 17
  • 24