I have a query with a self join that looks like this,
select t1., t2. from table t1 left outer join table t2 on t2.LFT < t1.LFT and t2.RGT > t1.RGT AND t2.REG_CODE_PAR = 'ALL' AND t1.STATUS_CODE = 'A' AND t2.STATUS_CODE = 'A'
I'm using @NamedNativeQuery with a result set mapping to get the result.
@NamedNativeQuery(
name="findTree",
query="..... the query above",
resultSetMapping = "regionT")
With the following result set mapping
@SqlResultSetMapping(name = "regionT" , entities ={
@EntityResult(
entityClass = Tree.class
fields = {
@FieldResult(name = "regCode", column = "REG_CODE")
@FieldResult(name = "rgt", column = "RGT"),
@FieldResult(name = "lft", column = "LFT"),
@FieldResult(name = "name", column = "NAME"),
@FieldResult(name = "regCodePar", column = "REG_CODE_PAR"),
@FieldResult(name = "statusCode", column = "STATUS_CODE")
}
),
@EntityResult(
entityClass = TreeSelf.class
fields = {
@FieldResult(name = "regCode1", column = "REG_CODE")
@FieldResult(name = "rgt1", column = "RGT"),
@FieldResult(name = "lft1", column = "LFT"),
@FieldResult(name = "name1", column = "NAME"),
@FieldResult(name = "regCodePar1", column = "REG_CODE_PAR"),
@FieldResult(name = "statusCode1", column = "STATUS_CODE")
}
)
})
The entity class contains looks like this.
@NamedNativeQuery(...)
@@SqlResultSetMapping(...) @Entity @Table(name = "table") public class Tree implements Serializable {
@Id
@Column(name = "REG_CODE")
private String regCode; ... ..getters and setters...}
When I run the query using em.createQuery("findTree"), I get the exact same object in both
the 1st and 2nd elements of the returned object array. Even if I create a class called TreeSelf that is identical to Tree and use it as the 2nd
EntityResult instead of having 2 EntityResults using the same entityClass, I get the same
result.
Can someone point out what's wrong with the configuration?