[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3655) Select Query Using JPA and Static Inner Class
John Sublette (JIRA)
noreply at atlassian.com
Tue Apr 21 11:04:17 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32959#action_32959 ]
John Sublette commented on HHH-3655:
------------------------------------
I've noticed the same problem in Hibernate 3.2.4-sp1. I have a class that contains a static inner sub-class (which has some extra fields). The identical query works with the main class, but not with the inner sub-class.
This needs to be corrected, or the documentation changed to reflect that no inner classes can be used this way.
e.g.
package com.foo;
public class Foo {
int fooCount;
public Foo(int fooCount) {
this.fooCount = fooCount;
}
public static class FooWithMoreFoo extends Foo {
String fooDescription;
public FooWithMoreFoo(int fooCount) {
this(fooCount, "Undescribable");
}
public FooWithMoreFoo(int fooCount, String fooDescription) {
super(fooCount);
this.fooDescription = fooDescription;
}
}
}
The following query would work: "SELECT new com.foo.Foo(f.count) FROM DatabaseFoo f WHERE f.count > 5)"
This wouldn't work: "SELECT new com.foo.Foo.FooWithMoreFoo(f.count) FROM DatabaseFoo f WHERE f.count > 5)"
nor would: "SELECT new com.foo.Foo.FooWithMoreFoo(f.count, f.description) FROM DatabaseFoo f WHERE f.count > 5)"
> Select Query Using JPA and Static Inner Class
> ---------------------------------------------
>
> Key: HHH-3655
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3655
> Project: Hibernate Core
> 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.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list