Projectable.uniqueResult() semantics

Bug #717563 reported by cowwoc on 2011-02-12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Undecided
Unassigned

Bug Description

It's not clear what happens if Projectable.uniqueResult() is invoked on a query that returns multiple results.

Is this ok : for multiple results only the first one is returned

The details are implementation specific

Changed in querydsl:
status: New → Fix Committed
cowwoc (gili) wrote :

Timo,

The text you mentioned is okay but I am somewhat concerned about the method name. Coming from JPA I am somewhat unused to the method throwing an exception if multiple matches are found. I guess I could push this integrity-checking into the database using the UNIQUE keyword, but then I'm strongly in favor of renaming the method to something along the lines of firstResult(). The current method name implies that the result is unique, which is not necessarily true.

cowwoc (gili) wrote :

"somewhat unused to the method throwing an exception" should read "somewhat used to the method throwing an exception"

firstResult() also somewhat implies that the result is ordered, which it is not necessarily.

Maybe I should instead always throw an Exception if more than one result is found. Then this would be consistent. For Hibernate and JPA this would already be the case and could easily be applied to the other modules.

cowwoc (gili) wrote :

I would be fine with that.

summary: - Projectable.uniqueResult() Javadoc does not discuss what happens if
- multiple matches are found
+ Projectable.uniqueResult() should throw an Exception on multiple results
Changed in querydsl:
status: Fix Committed → In Progress
summary: - Projectable.uniqueResult() should throw an Exception on multiple results
+ Projectable.uniqueResult() semantics
Changed in querydsl:
status: In Progress → Fix Committed

Released in 2.1.2

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers