SQL/DDL modifier
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.
@Check
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 ( id int8 not null, description varchar(255), price float8 not null, primary key (id), check (price >= 0) )
@ColumnDefault
Another DDL modifier is the Hibernate annotation...