[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3655) Select Query Using JPA and Static Inner Class

Pirabu G (JIRA) noreply at atlassian.com
Thu Jan 26 02:53:10 EST 2012


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45250#comment-45250 ] 

Pirabu G commented on HHH-3655:
-------------------------------

Hi Steve,

  Thank you, Its Work fine for static inner class JPA...

> Select Query Using JPA and Static Inner Class
> ---------------------------------------------
>
>                 Key: HHH-3655
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3655
>             Project: Hibernate ORM
>          Issue Type: Bug
>    Affects Versions: 3.3.1
>         Environment: Hibernate Version 3.3.1 GA, using JPA.  MySQL DB.
>            Reporter: Caine Lai
>         Attachments: HibernateStaticInnerClassBug.zip
>
>
> I want to collect some statistics using JPA and return them all as a value object to my web tier.  In my value object I have a static inner class I would like to use for the JPA query.
> My Class: 
> public class GeneralVendorStatsVO { 
>     
>    private List<StatusCounts> statusCounts = new ArrayList<StatusCounts>(); 
>     
>    /** 
>     * Inner class for holding status counts for vendors. 
>     */ 
>    public static class StatusCounts { 
>        
>       private UserStatus status; 
>       private Long count; 
>        
>       public StatusCounts(UserStatus status, Long count) { 
>          this.status = status; 
>          this.count = count; 
>       } 
>   
>       public UserStatus getStatus() { return status; } 
>       public void setStatus(UserStatus status) { this.status = status; } 
>   
>       public Long getCount() { return count; } 
>       public void setCount(Long count) { this.count = count; } 
>    } 
>     
>    // ********************** Accessor Methods ********************** // 
>   
>    public List<StatusCounts> getStatusCounts() { return statusCounts; } 
>    public void setStatusCounts(List<StatusCounts> statusCounts) { this.statusCounts = statusCounts; } 
> }
> And here is the method I am trying to execute: 
> public GeneralVendorStatsVO getGeneralVendorStats() { 
>           
>    GeneralVendorStatsVO vo = new GeneralVendorStatsVO(); 
>     
>    // Get the status counts. 
>    String queryString = "SELECT new vo.stats.vendor.GeneralVendorStatsVO.StatusCounts(user.status, count(user)) FROM User user GROUP BY user.status"; 
>    Query query = this.em.createQuery(queryString); 
>    List<GeneralVendorStatsVO.StatusCounts> statusCounts = query.getResultList(); 
>    vo.setStatusCounts(statusCounts); 
>    for (GeneralVendorStatsVO.StatusCounts entry : statusCounts) { 
>       log.debug("Status: " + entry.getStatus()+ "Count: " + entry.getCount()); 
>    } 
>    return vo; 
> }
> The error: 
> org.hibernate.hql.ast.QuerySyntaxException: Unable to locate class [vo.stats.vendor.GeneralVendorStatsVO.StatusCounts] 
> I don't know why this would not work, when I can do: 
> new GeneralVendorStatsVO.StatusCounts(UserStatus.APPROVED, 200L)
> I was told I should open an issue because it seems like a bug.  More info here:  http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=004912

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list