Projectable.uniqueResult(): How can I differentiate between no results versus a column containing null?

Asked by cowwoc

The Javadoc for Projectable.uniqueResult() says that it will return null if no result is found, but what happens if the column being returned is nullable? What happens if a unique result *is* found but the column being retrieved happens to be null?

The ambiguity only exists if a user is returning exactly one column.

Question information

Language:
English Edit question
Status:
Answered
For:
Querydsl Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Timo Westkämper (timo-westkamper) said :
#1

I guess the only way to get rid of this ambiguity with the standard API is to use iterate(...) or list(...). Alternatively you can subclass your query class and customize uniqueResult(...) to throw Exceptions on empty results.

Revision history for this message
cowwoc (gili) said :
#2

Please consider updating the Javadoc to reflect this ambiguity: "returns null if no result is found or if the column is null. To avoid ambiguity do X or Y"

Revision history for this message
cowwoc (gili) said :
#3

Timo,

Are you willing to make this Javadoc change? Did you want me to open a separate RFE for it?

Revision history for this message
Timo Westkämper (timo-westkamper) said :
#4

Sorry for the delay. I just updated the docs. Please use the Forum instead. I tried to disable Launchpad Answers for Querydsl, but apparently it didn't work.

Can you help with this problem?

Provide an answer of your own, or ask cowwoc for more information if necessary.

To post a message you must log in.