The database: E-R diagram

This is the E-R (Entity-Relationship) diagram of the database that we are going to use:

The database: E-R diagram

Tip

About the E-R diagram

An Entity-Relationship (E-R) diagram is, in short, used to represent a relational database. It describes the information that will be stored in the database in terms of the entities and connections between them (relationships).

An entity is an object (for example a person or a group) that can be uniquely identified and is independent (that is, it can "live" alone).

A relationship describes how two or more entities are related to each other.

Both entities and relationships can have attributes. To find more about ER diagrams, you can read http://en.wikipedia.org/wiki/Entity-relationship_model.

As you can see, it's quite simple it is all based around the contact entity. Each contact can also be a user of the web application (having a username and a password set). Also, more fields can be associated with a different type of custom field (such as URL, email, and so on) and a label (home, work, and so on depending on the type). A contact can have one or more addresses associated with a label (such as home, work, and so on).

Users can create one or more groups of contacts with a different color for each one. Finally, a list of files (such as a CV or other) can be associated with each contact.

The database is ready; we can go on to create the project structure and the Java Persistent API (JPA) entities connected to the database tables.

Note

What is JPA?

We have talked about JBoss Seam and Facelets, but this is the first time that we have talked about JPA. JPA is the acronym for Java Persistence API and it is the standard API for persistence and object/relational mapping for the Java (SE and EE) platform.

This is another must-know technology. It is very useful to manage (query, insert, update) persistent data connected to a DBMS in a simple way. The main concept here is the entity it is a POJO that normally represents a table in a database, and every instance of it represents an individual row in the table.

To make an example, if you want to insert a new row in a database table, you have just to create an instance of the entity class that represents the table, then fill the fields of the entity with data, and call the persist method to insert a new row into the database. You don't have to write a single line of SQL (JPA is going to do that work for you). Also, when you query the database, you use a SQL-like language (called Java Persistence Query Language (JPQL)) and the result will be a list of objects(java.util.list) these perfectly fit into a JSF application.

Connecting entities with tables is very simple using annotations (inside the class itself) or XML descriptor files.

There are some good implementations of the JPA. We are going to use the one from JBoss, which you may know Hibernate. It was an ORM framework prior to the existence of JPA (that has got many ideas from it) and it's included in the project that seam-gen generates for us.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.21.47