Search code examples
hibernatehqlself-join

using HQL in one to many relations when hibernate generate own table and we've not that table/entity in our Entity Models


when i try model a oneToMany self relation on RuleEntity, hibernate generate rule_ruletable in db to handling this matter , now the question is : because i haven't this entity(rule_rule) in my domain so i can't do HQL to find relatedRules that related to some rule :)
how can i do this?

RuleEntity

@ManyToMany(fetch = FetchType.LAZY)
private Set<RuleEntity> relatedRules;

the point is --> for some business reasons i cant't use Native Sql in this situation

tnx


Solution

  • ok Dudes, i find it :)

    select r.ruleName from RuleEntity r JOIN r.relatedRules rr where rr.ruleName = 'myRule'

    this query find RuleEntities which have relatedRule with name "myRule"