View entity with view entities as member-entity without sub-select

Is using sub-select the only way to include view entities as member-entities?

I attempted to create a view entity using other view entities as member-entity, but the generated SQL resulted in expressions like subAlias.nestedAlias.fieldName in the select and join clauses.

To address this, I made the following changes:

  1. Modified the getBasicFieldColName method in EntityDefinition.groovy like this:

  1. Modified the makeFullColumnName method:

  2. Altered the appendJoinConditions method in EntityFindBuilder.java to use aliasName


  3. Adjusted the makeSqlViewTableName method to generate AS aliasName for fields from view entities:

After these modifications, the generated SQL became correct as long as the query doesn’t include any econdition.

However, there are still a few issues when including conditions:

  1. makeSqlViewTableName calls makeSqlFromClause recursively. Inside makeSqlFromClause, we collect used fields by adding all fields from localWhereCondition, which includes fields unrelated to the current nested view entity.
  2. If we want to filter the localWhereCondition in the recursive calls, what would be the best way to track the field reference chain?
  3. How should I handle the return value from makeSqlFromClause? It returns an outWhereCondition.

I still don’t fully understand the logic behind the SQL generation in EntityFindBuilder.

1 Like