-->
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.  [ 2 posts ] 
Author Message
 Post subject: Strange results with SqlResultSetMapping
PostPosted: Wed Apr 28, 2010 5:50 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Hi

I'm getting strange results for a native query and @SqlResultSetMapping. I was wondering if anyone could help me?

If I look at the query coming out in the logs, and then paste it into MySQL query browser, I get the correct set of results. However Hibernate maps these into a list of objects, and that list doesn't quite match the expected results.

This is the query that Hibernate tells me it's executing

Code:
Hibernate: select ds.dept_code as 'dept', ds.status_code as 'statusCode', count(*) as 'count' from account a, department_status ds where a.department_status_code = ds.department_status_code and a.status_code = 'S' and a.state = 'new' group by 1 order by 2, 1
769609 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '22' as column: count
769609 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'AD' as column: dept
769609 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769625 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '15' as column: count
769625 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'AF' as column: dept
769625 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769625 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '5' as column: count
769625 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'AN' as column: dept
769625 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769625 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '15' as column: count
769625 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '96' as column: count
769719 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'BN' as column: dept
769719 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769719 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '18' as column: count
769734 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'CA' as column: dept
769734 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769734 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '68' as column: count
769828 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'CM' as column: dept
769828 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769828 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '28' as column: count
769844 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'CX' as column: dept
769844 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769844 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '26' as column: count
769937 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'ED' as column: dept
769937 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769937 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '23' as column: count
769937 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'EL' as column: dept
769937 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
769937 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '18' as column: count
770031 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '11' as column: count
770031 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'ES' as column: dept
770031 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770031 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '2' as column: count
770047 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'EU' as column: dept
770047 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770140 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '11' as column: count
770140 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '17' as column: count
770140 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'FI' as column: dept
770140 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770140 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '25' as column: count
770140 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'HF' as column: dept
770234 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770234 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '11' as column: count
770234 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '57' as column: count
770234 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'HR' as column: dept
770250 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770250 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '14' as column: count
770344 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'LA' as column: dept
770344 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770344 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '38' as column: count
770344 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'LW' as column: dept
770359 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770359 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '12' as column: count
770437 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'MM' as column: dept
770437 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770437 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '13' as column: count
770437 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'NU' as column: dept
770437 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770453 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '13' as column: count
770547 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '107' as column: count
770547 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'PM' as column: dept
770547 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770547 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '12' as column: count
770547 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '16' as column: count
770547 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'RD' as column: dept
770640 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770640 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '12' as column: count
770640 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '11' as column: count
770640 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '13' as column: count
770640 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '17' as column: count
770640 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '19' as column: count
770750 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'UI' as column: dept
770750 [http-8080-4] TRACE org.hibernate.type.StringType  - returning 'S' as column: statusCode
770750 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '18' as column: count
770750 [http-8080-4] TRACE org.hibernate.type.IntegerType  - returning '16' as column: count


An example of the strange results; 'MM' only appears once in the output above, but the resulting List that I get contains it twice.

@Entity
@SqlResultSetMapping(name="reportQueryMapping",
entities=@EntityResult(entityClass=ReportQueryResult.class))

ReportQueryResult has the three fields defined, and the 'count' field in this class is annotated with @Id. I suspect that might be the problem actually...

Thanks


Top
 Profile  
 
 Post subject: Re: Strange results with SqlResultSetMapping
PostPosted: Wed Apr 28, 2010 6:03 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
That @Id was it. I defined the ID on the other two fields instead and the results look sensible now


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.