简体   繁体   English

为什么@NotNull工作时@AssertTrue不工作?

[英]Why @AssertTrue doesn't work while @NotNull works?

I'm working on a entity library. 我正在研究实体库。 I put some bean-validation annotations on my Entities. 我在实体上放置了一些bean验证注释。

I strongly believe a bean-validation implementation in on the class path. 我坚信类路径中的bean验证实现。 @javax.validation.constraints.NotNull works and @javax.validation.constraints.AssertTrue doesn't work. @javax.validation.constraints.NotNull有效,而@javax.validation.constraints.AssertTrue不起作用。

class MyEntity {

    @AssertTrue // does't work
    public boolean hey() {
        return false;
    }

    @NotNull // works; violation while persist
    private String some;
}

What possibly did I do wrong with it? 我可能做错了什么?

I uses org.hibernate:hibernate-validator and changing it with org.apache.bval:bval-jsr doesn't make any difference. 我使用org.hibernate:hibernate-validator并使用org.apache.bval:bval-jsr对其进行更改没有任何区别。

UPDATE 更新

The method is actually invoked. 该方法实际上是被调用的。 I check the log. 我检查日志。

Here comes my method. 这是我的方法。

@AssertTrue(message = "a property must be eclusively system or owned")
private boolean execlusivelySystemOrOwned() {
    logger.info("execlusivelySystemOrOwnded()");
    final boolean result = system ^ (getOwner() != null);
    logger.log(Level.INFO, "result: {0}", result);
    return result;
}

I think I found the answer. 我想我找到了答案。

https://stackoverflow.com/a/12950573/330457 https://stackoverflow.com/a/12950573/330457

I had to rename the method to isExeclusivelySystemOrOwned . 我不得不将方法重命名为isExeclusivelySystemOrOwned

That's why it's called Bean -Validation. 这就是为什么将其称为Bean -Validation。

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

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