Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Possible bug retrieving single Boolean column
Possible bug retrieving single Boolean column [message #635151] Mon, 25 October 2010 18:53 Go to next message
Brendan Healey is currently offline Brendan HealeyFriend
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 12:59 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
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 13:00]

Report message to a moderator

Re: Possible bug retrieving single Boolean column [message #635882 is a reply to message #635151] Thu, 28 October 2010 13:36 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is very odd.

What SQL is generated, if you execute the same SQL what result do you get?

(FYI initializing your field to false should not have any issues, and should not affect what is inserted).


James : Wiki : Book : Blog : Twitter
Re: Possible bug retrieving single Boolean column [message #1461084 is a reply to message #635151] Tue, 04 November 2014 07:21 Go to previous message
manuel jaehnig is currently offline manuel jaehnigFriend
Messages: 1
Registered: November 2014
Junior Member
Good morning together,

so here is a 5 year old thread which fits very good to my own problem, maybe we could restart the conversation about it.

in my oracle database i have a column with the datatype Number(1,0) and its not nullable.

In the code the field is declared like this:
   @Column(name = "VO_RELEVANTFLAG", nullable = false)
   private boolean                        voRelevantflag;


My query:

  query = entityManager.createQuery("SELECT x.voRelevantflag" //
                                             + "FROM " + AuBE.class.getSimpleName() );

      final Object resultObject = query.getResultList();


Like the creator of this thread i got FALSE if the column is 0 but i got an empty list if the column is 1.

I have updated the columns (switched between 1 and 0) via the oracle sql developer so the value is definitely set and if i execute the sql statement in the sql developer i can see the correct values.

I have tested it with EclipseLink 3.2.0 (which we are currently using) and newer versions like 3.4.0 and 2.6.0-M3 but nothing has changed.
How is this possible? Is this an old bug and noone else cares?

Thank you for you help.
kind regards
Manuel
Previous Topic:Can't find orm.xml in <jar-file>
Next Topic:AuditingEntityListener - updating on child add
Goto Forum:
  


Current Time: Tue Apr 23 07:44:23 GMT 2024

Powered by FUDForum. Page generated in 0.03139 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top