March 14th, 2008
Improving schema DDL Like DDL for stored procedures, you can add trigger declarations to your Hibernate mapping metadata with the element for inclusion in the generated DDL. Finally, integrity constraints can be checked immediately when a data-modification statement is executed, or the check can be deferred until the end of a transaction. The violation response in SQL databases is usually rejection, without any possibility of customization. We now have a closer look at the implementation of integrity constraints. 8.3.3 Adding domains and column constraints The SQL standard includes domains, which, unfortunately, not only are rather limited but also are often not supported by the DBMS. If your system supports SQL domains, you can use them to add constraints to datatypes: create domain EMAILADDRESS as varchar constraint DOMAIN_EMAILADDRESS check ( IS_EMAILADDRESS(value) ); You can now use this domain identifier as a column type when creating a table: create table USERS ( … USER_EMAIL EMAILADDRESS(255) not null, … ); The (relatively minor) advantage of domains in SQL is the abstraction of common constraints into a single location. Domain constraints are always checked immediately when data is inserted and modified. To complete the previous example, you also have to write the stored function IS_EMAILADDRESS (you can find many regular expressions to do this on the Web). Adding the new domain in a Hibernate mapping is simple as an sql-type:
With annotations, declare your own columnDefinition: @Column(name = “USER_EMAIL”, length = 255, columnDefinition = “EMAILADDRESS(255) not null”) String email;
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.