May 2016
Beginner
204 pages
4h 22m
English
In this section, we will discuss annotations that modify the SQL or the DDL used by Hibernate to perform a query or generate schema objects. The DDL modifying annotations are important if you use Hibernate to generate your tables.
Using the @Check Hibernate annotation, you can add the CHECK constraints to your table. The constraint defined in the @Check annotation uses the syntax that is supported by the database of your choice.
The following listing adds a constraint to the price column:
@Entity
@Check(constraints = "price >= 0")
public class Item {
@Id
@GeneratedValue
private long id;
private String description;
private double price;
// setters and getters
}The DDL generated using PostgreSQL, is shown here:
create table Item ...
Read now
Unlock full access