Ibatis - Preparing to Use SQL MapsIntroduction This brief tutorial will take you through a walkthrough of a typical use of SQL Maps. The details of each of the topics below can be found in the SQL Maps developer guide available from http://ibatis.apache.org Preparing to Use SQL Maps The SQL Maps framework is very tolerant of bad database models and even bad object models. Despite this, it is recommended that you use best practices when designing your database (proper normalization) and your object model. By doing so, you will get good performance and a clean design. The easiest place to start is to analyze what you’re working with. What are your business objects? What are your database tables? How do they relate to each other? For the first example, consider the following simple Person class that conforms to the typical JavaBeans pattern.
package examples.domain;
//imports implied…. public class Person { private int id; private String firstName; private String lastName; private Date birthDate; private double weightInKilograms; private double heightInMeters; public int getId () { return id; } public void setId (int id) { this.id = id; } //…let’s assume we have the other getters and setters to save space… } How does this Person class map to our database? SQL Maps doesn’t restrict you from having relationships such as table-per-class or multiple-tables-per-class or multiple-classes-per-table. Because you have the full power of SQL available to you, there are very few restrictions. For this example, let’s use the following simple table which would be suitable for a table-per-class relationship: Person.sql
CREATE TABLE PERSON(
PER_ID NUMBER (5, 0) NOT NULL, PER_FIRST_NAME VARCHAR (40) NOT NULL, PER_LAST_NAME VARCHAR (40) NOT NULL, PER_BIRTH_DATE DATETIME , PER_WEIGHT_KG NUMBER (4, 2) NOT NULL, PER_HEIGHT_M NUMBER (4, 2) NOT NULL, PRIMARY KEY (PER_ID) ) |