Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 325417

Summary: Cant execute count on SQL Server 2000
Product: z_Archived Reporter: D-neg <Matayo>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P2 CC: Matayo, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: sqlserver

Description D-neg CLA 2010-09-16 05:10:30 EDT
Build Identifier: 2.0.0.v20091127-r5931

I want to count the number of rows in my query result for pagination, but i obtain exception. I develop on Netbeans Platform Framework with MS SQL 2000 for Database Server

The code

protected CriteriaBuilder cbCount;
    protected CriteriaQuery<Long> criteriaQueryCount;
protected EntityManager em = (EntityManager) EntityManagerSingleton.getDefault().getEntityManager();
protected Root<DataIndividual> emp;
…..
cbCount = em.getCriteriaBuilder();
        criteriaQueryCount = cb.createQuery(Long.class);
        criteriaQueryCount.select(cbCount.count(emp));
        criteriaQueryCount.distinct(true);
….
TypedQuery<Long> qCount = em.createQuery(criteriaQueryCount);

 System.out.println("count total " + qCount.getSingleResult());

Exception:

Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The count aggregate operation cannot take a uniqueidentifier data type as an argument.
Error Code: 409
Call: SELECT DISTINCT COUNT(IndividualGUID) FROM dataIndividual
Query: ReportQuery(referenceClass=DataIndividual sql="SELECT DISTINCT COUNT(IndividualGUID) FROM dataIndividual")
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:686)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:529)
	at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:529)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:205)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:191)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:262)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:618)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2537)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2480)
	at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:838)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:702)
	at org.unhcr.rams.exchange.loadData.LoadFromProgresVisualPanel3.loadDataFromproGresDatabase(LoadFromProgresVisualPanel3.java:291)
	at org.unhcr.rams.exchange.loadData.LoadFromProgresWizardPanel3.storeSettings(LoadFromProgresWizardPanel3.java:67)
	at org.unhcr.rams.exchange.loadData.LoadFromProgresWizardPanel3.storeSettings(LoadFromProgresWizardPanel3.java:19)
	at org.openide.WizardDescriptor.setValueOpen(WizardDescriptor.java:1342)
	at org.openide.WizardDescriptor.setValue(WizardDescriptor.java:1320)
	at org.netbeans.core.windows.services.NbPresenter$ButtonListener.actionPerformed(NbPresenter.java:1268)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.Component.processMouseEvent(Component.java:6267)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6032)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4630)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4460)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
	at java.awt.Dialog$1.run(Dialog.java:1046)
	at java.awt.Dialog$3.run(Dialog.java:1098)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.Dialog.show(Dialog.java:1096)
	at org.netbeans.core.windows.services.NbPresenter.superShow(NbPresenter.java:985)
	at org.netbeans.core.windows.services.NbPresenter.doShow(NbPresenter.java:1019)
	at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:1007)
	at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:115)
	at org.openide.util.Mutex$1AWTWorker.run(Mutex.java:1370)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The count aggregate operation cannot take a uniqueidentifier data type as an argument.
	at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
	at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
	at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
	at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
	at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
	at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
	at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
	at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
	at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
	at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
	at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
	at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
	at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:891)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:601)
	... 66 more


Reproducible: Always
Comment 1 Tom Ware CLA 2010-09-20 09:26:53 EDT
You should be able to workaround this issue by counting an attribute of emp instead of emp itself.
Comment 2 D-neg CLA 2010-09-20 09:38:08 EDT
(In reply to comment #1)
> You should be able to workaround this issue by counting an attribute of emp
> instead of emp itself.

Dear Tom,

Thanks for your reply,

But the problem is only Primary key is unique in my table, and i want to make pagination for to see all rows by page in my JTable.

Thanks.
Stanyslas Matayo
Comment 3 Tom Ware CLA 2010-09-20 09:41:25 EDT
How is the object you are counting mappeed?

How is the table created?
Comment 4 Tom Ware CLA 2010-09-22 16:07:37 EDT
Setting Target and Prioirty.  See the following page for details of what these
fields mean:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Note: We have many tests using Count on SQL Server that pass, without the information requested above, we will have to close this bug as WORKSFORME.
Comment 5 Tom Ware CLA 2010-09-30 11:45:24 EDT
Closing as worksforme because of the fact that our count tests pass and no additional feedback about what is failing.
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:04:21 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink