[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4044) ejbql select count() and composite keys problem

Rock (JIRA) noreply at atlassian.com
Tue Aug 9 08:27:04 EDT 2011


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

Rock commented on HHH-4044:
---------------------------

Same problem with:
HQL: "SELECT COUNT(DISTINCT(userRole)) FROM UserRole userRole"
generated SQL: select count(distinct(userrole0_.roleId, userrole0_.userId)) ...

It works with:
HQL: "SELECT COUNT(DISTINCT(userRole.id)) FROM UserRole userRole"
generated SQL: generated SQL: select count(distinct userrole0_.roleId, userrole0_.userId) ...

Problems with group by too. It´s generating something like
...group by
(userrole0_.roleId,
userrole0_.userId)
order by...

> ejbql select count() and composite keys problem
> -----------------------------------------------
>
>                 Key: HHH-4044
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4044
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.6
>         Environment: Jboss 4.2.2, JDK 1.5.18, Seam 2.1.2, MSSQL2000
>            Reporter: Thierry Accart
>            Priority: Critical
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> Hi
> we're using seam 2.1.2 on JBoss 4.2.2 with JDK 1.5.18.
> Our db is hosted on mssql server.
> our persistence.xml contains sets hibernate.dialect to org.hibernate.dialect.SQLServerDialect.
> UserRole is an entity containing userid and roleid as a composite key.
> When the following  ejbql query is run :
> select count(userRole) from UserRole userRole
> sql receives the following statement : 
> declare @P1 int
> set @P1=NULL
> declare @P2 int
> set @P2=0
> declare @P3 int
> set @P3=0
> exec sp_cursorprepexec @P1 output, @P2 output, NULL, N'select count((userrole0_.roleId, userrole0_.userId)) as col_0_0_ from TP_UM_UserRole userrole0_', 16, 8193, @P3 output
> select @P1, @P2, @P3
> the   count((userrole0_.roleId, userrole0_.userId)) is not understood by mssql server, causing  an error " Incorrect syntax near ','."
> I think that a simple select count (*) would work fine.

--
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