5.5. Model Components

This piece of configuration is all you need to write in order to specify that the 'Name' class is actualy only a part of a table:
	<orm:components> 
		<orm:component name="Name"/>
	</orm:components>
The java class associated with this component is listed below:
public class Name {

	protected String firstName;

	protected String lastName;
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
We will use the name component within the class 'Author' that has this java code class:
public class Author {
	
	private int authorId;
	
	private Name name;
	
	private Set books = new HashSet();
	
	public int getAuthorId() {
		return authorId;
	}

	public void setAuthorId(int authodId) {
		this.authorId = authodId;
	}

	public Set getBooks() {
		return books;
	}

	public void setBooks(Set books) {
		this.books = books;
	}

	public Name getName() {
		return name;
	}

	public void setName(Name name) {
		this.name = name;
	}

}
As you can see, we also added a list of books to the author as an author can have several books. With all this and after we add some more properties to the book class, the table for the 'author' and the 'book' look like this:
+--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| book_id      | int(11)      | NO   | PRI |         | auto_increment |
| title        | varchar(255) | NO   |     |         |                |
| publish_date | datetime     | NO   |     |         |                |
| author_id    | int(11)      | YES  | MUL |         |                |
| editor_id    | int(11)      | YES  | MUL |         |                |
+--------------+--------------+------+-----+---------+----------------+
and
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| author_id  | int(11)      | NO   | PRI |         | auto_increment |
| first_name | varchar(255) | NO   |     |         |                |
| last_name  | varchar(255) | NO   |     |         |                |
+------------+--------------+------+-----+---------+----------------+