Skip to content

Need help in mapping a custom select query with @Query to java model in case of one-to-many #1798

Closed
@margamraviteja

Description

@margamraviteja
@Table("my_rule")
public class MyRule {

	@Id
	@Column("rule_id")
	private Long ruleId;

	@Column("rule_name")
	private String ruleName;

	@Column("rule_type")
	private String ruleType;

	@Column("rule_description")
	private String ruleDescription;

	@Transient
	private Set<MyRuleCondition> conditions = new HashSet<>();

}
@Table("my_rule_condition")
public class MyRuleCondition {

	@Id
	@Column("condition_id")
	private Long conditionId;

	@Column("rule_id")
	private Long ruleId;

	@Column("comparison_field")
	private String comparisonField;

	@Column("comparison_operator")
	private String comparisonOperator;

	@Column("comparison_value")
	private String comparisonValue;

}
	@Query(value = "select r.rule_id, r.rule_name, r.rule_type, r.rule_description, "
			+ "c.comparison_field, c.comparison_operator, c.comparison_value "
			+ "from my_rule r left join my_rule_condition c on r.rule_id = c.rule_id")
	List<MyRule> customFind();

When I call the customFind method, the rule object duplicated with conditions empty

Activity

schauder

schauder commented on May 31, 2024

@schauder
Contributor

Either only select the aggregate root or provide a custom ResultSetExtractor.

This issue tracker is for bug reports and feature/improvement requests.
This question is more of a usage questions. Those should be asked at Stackoverflow and be tagged with spring-data-jdbc.
By using Stackoverflow, the community can assist and the questions and their answers can more easily be found using the search engine of your choice.

self-assigned this
on May 31, 2024
added
for: stackoverflowA question that's better suited to stackoverflow.com
and removed on May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: stackoverflowA question that's better suited to stackoverflow.com

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @schauder@margamraviteja@spring-projects-issues

      Issue actions

        Need help in mapping a custom select query with @Query to java model in case of one-to-many · Issue #1798 · spring-projects/spring-data-relational