Siena / Play / GAE parses boolean field wrong: 0 = true

165 views Asked by At

I'm having a hard time working with booleans in Siena 2.0.7 and Play 1.2.4.

In the constructor of my class I set the boolean to FALSE. Then I save the object. In the datastore viewer I can see the boolean field saved as 0.

When I retrieve that row from the database, the boolean field is parsed as TRUE. I'm lost, hope you can help!

Class:

@Entity
public class CMessage extends EnhancedModel 
{
    public CMessage() {
        this.isProcessed = false;
    }

public CMessage(String bridgeId) {
    this.bridgeId = bridgeId;

    // set createdDate & expireDate
    this.createdDate = new Date();
    this.isProcessed = false;
}

@Id(Generator.AUTO_INCREMENT)
public Long id;

@NotNull
public String bridgeId;

@NotNull
@DateTime
public Date createdDate;

@NotNull
public boolean isProcessed;

}

Test:

    CMessage msg = new models.CMessage("bridge");
    Logger.info("saved isProcessed = %s", msg.isProcessed); // always gives false
    msg.save();

    Logger.info("saved isProcessed = %s", msg.isProcessed); // always gives false

    CMessage get = (CMessage) CMessage.findAll().get(0);
    Logger.info("got isProcessed = %s", get.isProcessed); // always gives true
    assertEquals(false, get.isProcessed);

note: i haven't tested on GAE itself, only on my dev machine. Maybe gae datastore does get it right...

2

There are 2 answers

2
Morgenstond On BEST ANSWER

Seems to be a bug in the current version of Siena: https://github.com/mandubian/siena/pull/18

1
mandubian On

It's quite weird that you get a True...
Could you try with a Boolean instead of a boolean to see if you have the same behavior?
Thanks