Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a @NotNull annotation for Ebean in Play Framework?

I want Ebean in Play Framework to make some columns in my tables 'not null'. Is it possible to the @NotNull annotation? If yes, which package should I import? I tried with import com.avaje.ebean.validation.NotNull; but I got an error saying this package can't be found.

like image 845
pmichna Avatar asked Dec 20 '25 19:12

pmichna


2 Answers

Note that the accepted answer is no longer correct.

com.avaje.ebean.validation.NotNull no longer exists and instead you can use javax.validation.constraints.NotNull

Secondly you do not need to specify @Column(nullable = false) if the @NotNull annotation is used. Ebean takes the existence of @NotNull as meaning that the DB column is not null and handles that appropriately.

like image 176
Rob Bygrave Avatar answered Dec 22 '25 09:12

Rob Bygrave


It's indeed com.avaje.ebean.validation.NotNull;

check this topic for solution:

https://groups.google.com/forum/#!msg/play-framework/azlPQ14XJ2I/tdOKUkYVAxAJ

BTW:

You need to use @Column(nullable = false) annotation if you want you column to be not nullable (the restriction will be enforced by DB).

@NotNull is for validation.

like image 25
Leo Avatar answered Dec 22 '25 08:12

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!