Querydsl: creating QBean projection with identical Path names

Created on 19 Feb 2015  ·  6Comments  ·  Source: querydsl/querydsl

I have two Pathes with identical property names (team.name and team.leader.name)

Projections.bean(QTeam.team, team.name, team.leader.name);

fails with

java.lang.IllegalArgumentException: Multiple entries with same key: name=team.leader.name and name=team.name
    at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:150)
    at com.google.common.collect.RegularImmutableMap.checkNoConflictInBucket(RegularImmutableMap.java:104)
    at com.google.common.collect.RegularImmutableMap.<init>(RegularImmutableMap.java:70)
    at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:254)
    at com.mysema.query.types.QBean.createBindings(QBean.java:72)
    at com.mysema.query.types.QBean.<init>(QBean.java:161)
    at com.mysema.query.types.QBean.<init>(QBean.java:95)
    at com.mysema.query.types.Projections.bean(Projections.java:63)

Most helpful comment

You can populate nested beans, but you will need to do so explicitly.

e.g.

Projections.bean(Team.class, team.name, 
  Projections.bean(Leader.class, team.leader.name).as("leader"))

Assuming that Leader is the type of the intermediate object.

All 6 comments

How do you want these to be applied to the bean?

I want only name of team and name of team leader, all other properties should be null. Isn't that natural?

QBean requires unique propert keys and doesn't support implicit intermediate property creation.

Does that mean by design I cannot use for instance MongoDB's projection for nested property and project MongoDB's document to java bean?

You can populate nested beans, but you will need to do so explicitly.

e.g.

Projections.bean(Team.class, team.name, 
  Projections.bean(Leader.class, team.leader.name).as("leader"))

Assuming that Leader is the type of the intermediate object.

OK, got it. Thanks. Would be nice to support more concise syntax.
Please consider moving this to enhancement or closing.

Was this page helpful?
0 / 5 - 0 ratings