-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SqlResultSetMapping with self join table
PostPosted: Thu Jul 22, 2010 9:33 pm 
Newbie

Joined: Sun Jul 18, 2010 10:56 pm
Posts: 2
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.
Code:
@NamedNativeQuery(
        name="findTree",
        query="..... the query above",
        resultSetMapping = "regionT"
)


With the following result set mapping
Code:
@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.
Code:
@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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.