Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA [count distinct] cause [javax.persistence.NoResultException: No entity found for query] #6332

Closed
vther opened this issue Jul 13, 2020 · 2 comments

Comments

@vther
Copy link

vther commented Jul 13, 2020

Bug Report

        Object singleResult = entityManager
            .createQuery("SELECT count (distinct i.orderItemId) from OrderItemEntity i where i.orderId = :orderId")
            .setParameter("orderId", 11111111111111111L) 
            .getSingleResult();

when use count distinct and entitymanager#getSingleResult() cause javax.persistence.NoResultException

Which version of ShardingSphere did you use?

[4.0.1 , 4.1.1] the bug remains

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Actual behavior

Reason analyze (If you can)

Actual SQL lack of count ,is it intentional or a bug?

[INFO ] 2020-07-13 17:01:36,835 --main-- [ShardingSphere-SQL] Logic SQL: select count(distinct orderiteme0_.order_item_id) as col_0_0_ from t_order_item orderiteme0_ where orderiteme0_.order_id=? 
[INFO ] 2020-07-13 17:01:36,835 --main-- [ShardingSphere-SQL] SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@6fbf5db2, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@509a6095), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@509a6095, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=60, distinctRow=false, projections=[AggregationProjection(type=COUNT, innerExpression=(distinct orderiteme0_.order_item_id), alias=Optional[col_0_0_], derivedAggregationProjections=[], index=-1)]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@57cabdc3, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@75bd28d, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@129c4d19, containsSubquery=false) 
[INFO ] 2020-07-13 17:01:36,835 --main-- [ShardingSphere-SQL] Actual SQL: demo_ds_0 ::: select DISTINCT orderiteme0_.order_item_id as col_0_0_ from t_order_item orderiteme0_ where orderiteme0_.order_id=? ::: [11111111111111111] 
[INFO ] 2020-07-13 17:01:36,835 --main-- [ShardingSphere-SQL] Actual SQL: demo_ds_1 ::: select DISTINCT orderiteme0_.order_item_id as col_0_0_ from t_order_item orderiteme0_ where orderiteme0_.order_id=? ::: [11111111111111111] 

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

.setParameter("orderId", 11111111111111111L)
this step is necessary

Example codes for reproduce this issue (such as a github link).

@kimmking
Copy link
Member

It has been fixed in #6118 for master branch 5.0.0-RC1

@vther
Copy link
Author

vther commented Jul 13, 2020

It has been fixed in #6118 for master branch 5.0.0-RC1

@kimmking
Will this fix merge into 4.x ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants