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

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

Issue actions