Reputation: 1300
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.
Upvotes: 0
Views: 408
Reputation: 692081
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
Upvotes: 2