| Possible bug retrieving single Boolean column [message #635151] |
Mon, 25 October 2010 14:53  |
Brendan Healey Messages: 12 Registered: May 2010 |
Junior Member |
|
|
Hi, this is a funny one, when the value of the testBoolean
column for row "testuser" is false this named query
works ok, when it's true I get NoResultException. A bug?
@NamedQuery(name = "User.Test", query = "SELECT u.testBoolean FROM User u WHERE u.userName = ?1"),
...
@Column(name = "testBoolean")
private Boolean testBoolean = false;
Query query = em.createNamedQuery("User.Test");
query.setParameter(1, "testuser");
try {
result = (Boolean) query.getSingleResult();
} catch (NoResultException e) {
result = null;
}
EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600
MySql 5.1.50-community
Regards,
Brendan.
|
|
|
| Re: Possible bug retrieving single Boolean column [message #635329 is a reply to message #635151] |
Tue, 26 October 2010 08:59   |
Chris Delahunt Messages: 863 Registered: July 2009 |
Senior Member |
|
|
Hello Brendan,
Feel free to file one, but I'm not sure you should be using getSingleResult() as it cannot distinguish between a null value and no values being returned. Try using getResultLitst(), but you will still get null values in the collection.
The problem is that you are defaulting the testBoolean value to false. Check the value in the database, but I believe that when you are persisting a value of false nothing is being sent to the database because nothing has changed. So the database column remains null. Try leaving the testBoolean uninitialized in the default constructor, and instead set it in other constructors and/or application code. This will cause EclipseLink to see that it has been set and persist a value to the database.
Best Regards,
Chris
[Updated on: Tue, 26 October 2010 09:00] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02092 seconds