简体   繁体   English

Siena / Play / GAE解析布尔字段错误:0 = true

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

I'm having a hard time working with booleans in Siena 2.0.7 and Play 1.2.4. 我很难在Siena 2.0.7和Play 1.2.4中使用布尔值。

In the constructor of my class I set the boolean to FALSE. 在我的类的构造函数中,我将布尔值设置为FALSE。 Then I save the object. 然后我保存对象。 In the datastore viewer I can see the boolean field saved as 0. 在数据存储区查看器中,我可以看到保存为0的布尔字段。

When I retrieve that row from the database, the boolean field is parsed as TRUE. 当我从数据库中检索该行时,布尔字段被解析为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. 注意:我还没有在GAE上测试,只在我的开发机器上测试过。 Maybe gae datastore does get it right... 也许gae datastore确实做对了......

似乎是当前版本的Siena中的一个错误: https//github.com/mandubian/siena/pull/18

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 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM