简体   繁体   中英

Why @AssertTrue doesn't work while @NotNull works?

I'm working on a entity library. I put some bean-validation annotations on my Entities.

I strongly believe a bean-validation implementation in on the class path. @javax.validation.constraints.NotNull works and @javax.validation.constraints.AssertTrue doesn't work.

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.

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

I had to rename the method to isExeclusivelySystemOrOwned .

That's why it's called Bean -Validation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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