0

I have the following @Entities

@Entity public class Configuration{ @OneToMany protected Map<String, Component> components; } 

and

@Entity public class Component{ protected String displayName; } 

I do not understand why this works, returning all Configurations

 CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class); Root<Configuration> pc = cq.from(Configuration.class); cq.select(pc); 

But if I do a MapJoin, even without setting any conditions, it does not return anything

 CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class); Root<Configuration> pc = cq.from(Configuration.class); MapJoin<Configuration, String, Component> mapJoin = pc.join(Configuration_.components); cq.select(pc); 

What am I missing? I'm at a loss, I've been through the tutorials, but have not found the answers I need. Any help much appreciated.

1 Answer 1

2

Because the join type is inner by default, which means that for a configuration to be returned it has to at least have one component. If none of your configurations have a component, nothing is returned.

The first query is equivalent to

select configuration.* from configuration 

And the second one is equivalent to

select configuration.* from configuration inner join component on component.id = configuration.id 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.