Sample Data Model and Common Classes
To keep things simple, we will use just one table, the CONTACT table, that we used throughout the chapters
about data access. Listings 13-4 and 13-5 show the data creation script (schema.sql) and test data
population script, respectively (test-data.sql).
Listing 13-4. Table Creation Script
DROP TABLE IF EXISTS CONTACT;
CREATE TABLE CONTACT (
ID INT NOT NULL AUTO_INCREMENT
, FIRST_NAME VARCHAR(60) NOT NULL
, LAST_NAME VARCHAR(40) NOT NULL
, BIRTH_DATE DATE
, VERSION INT NOT NULL DEFAULT 0
, UNIQUE UQ_CONTACT_1 (FIRST_NAME, LAST_NAME)
, PRIMARY KEY (ID)
);
Listing 13-5. Test Data Population Script
insert into contact (first_name, last_name, birth_date)
values ('Clarence', 'Ho', '1980-07-30');
insert into contact (first_name, last_name, birth_date)
values ('Scott', 'Tiger', '1990-11-02');
insert into contact (first_name, last_name, birth_date)
values ('John', 'Smith', '1964-02-28');
The entity class is simple too; Listing 13-6 shows the Contact class.
Listing 13-6. The Contact Class
package com.apress.prospring3.ch13.domain;
// Import statements omitted
@Entity
@Table(name = "contact")
@NamedQueries({
@NamedQuery(name="Contact.findAll", query="select c from Contact c"),
@NamedQuery(name="Contact.countAll", query="select count(c) from Contact c")
})
public class Contact implements Serializable {
private
Long id;
private
int version;
private
String firstName;
private
String lastName;
private
Date birthDate;
public Contact() {
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home