CHAPTER 8 Legacy databases and custom SQL If you want to create and drop the domain declaration automatically with the rest of your schema, put it into a mapping. SQL supports additional column constraints. For example, the business rules allow only alphanumeric characters in user login names: create table USERS ( … USERNAME varchar(16) not null check(regexp_like(USERNAME,’^[[:alpha:]]+$’)), … ); You may not be able to use this expression in your DBMS unless it supports regular expressions. Single-column check constraints are declared in Hibernate mappings on the mapping element:
Check constraints in annotations are available only as a Hibernate extension: @Column(name = “USERNAME”, length = 16, nullable = false, unique = true) @org.hibernate.annotations.Check( constraints = “regexp_like(USERNAME,’^[[:alpha:]]+$’)” ) private String username; Note that you have a choice: Creating and using a domain or adding a single-column constraint has the same effect. In the long run, domains are usually easier to maintain and more likely to avoid duplication. Let s look at the next level of rules: single and multirow table constraints. 8.3.4 Table-level constraints Imagine that you want to guarantee that a CaveatEmptor auction can t end before it started. You write the application code to prevent users from setting the start- Date and endDate properties on an Item to wrong values. You can do this in the user interface or in the setter methods of the properties. In the database schema, you add a single-row table constraint: create table ITEM ( … START_DATE timestamp not null,
We recommend high quality webhost to host and run your jsp application: christian web host services.
This entry was posted
on Friday, March 14th, 2008 at 4:13 pm and is filed under PHP5.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.