Creating Basic Financial JSF CRUD Application

[ This Blog Was Moved To : http://www.diknows.com ]


Today, I’m trying to revise my JSF, Hibernate Knowledge. I’m Creating a CRUD application.

Its a simple financial web application where there are admin/viewer privileges. The application will not be fully created in this tutorial.

The main idea is that the Admin can deposit/withdraw and the application should show his financial status to subscribed viewers.

In this basic tutorial I will introduce how to Generate JSF/Hibernate CRUD application using Netbeans 6.8 as a starting point for this small project.

I will use local MySQL as my database engine. And here is the ERD :

Financial Tutorial Image

ERD

And Here is the SQL :

USE financial;

/************ Update: Tables ***************/

/******************** Add Table: profile ************************/

/* Build Table Structure */
CREATE TABLE profile
(
 profileId INTEGER NOT NULL,
 profileName VARCHAR(50) NOT NULL,
 InsertBy VARCHAR(50) NOT NULL,
 UpdateBy VARCHAR(50) NOT NULL,
 InsertTime TIMESTAMP NOT NULL,
 UpdateTime TIMESTAMP NOT NULL,
 profile_state FLOAT NOT NULL DEFAULT 0,
 username VARCHAR(100) NULL
);

/* Table Items: profile */
ALTER TABLE profile ADD CONSTRAINT pkprofile
 PRIMARY KEY (profileId);

/******************** Add Table: record ************************/

/* Build Table Structure */
CREATE TABLE record
(
 recordId INTEGER NOT NULL,
 recordName VARCHAR(50) NOT NULL,
 InsertBy VARCHAR(50) NOT NULL,
 UpdateBy VARCHAR(50) NOT NULL,
 InsertTime TIMESTAMP NOT NULL,
 UpdateTime TIMESTAMP NOT NULL,
 profileId INTEGER NOT NULL,
 amount FLOAT NOT NULL DEFAULT 0,
 description TEXT NULL
);

/* Table Items: record */
ALTER TABLE record ADD CONSTRAINT pkrecord
 PRIMARY KEY (recordId);

/******************** Add Table: security ************************/

/* Build Table Structure */
CREATE TABLE security
(
 username VARCHAR(100) NOT NULL,
 password VARCHAR(20) NOT NULL,
 security_role VARCHAR(20) NOT NULL DEFAULT 'user'
);

/* Table Items: security */
ALTER TABLE security ADD CONSTRAINT pksecurity
 PRIMARY KEY (username);

/* Set Comments */
EXEC sp_addextendedproperty 'MS_Description', 'user or admin', 'user', 'schemaA',
 'table', 'security', 'column', 'security_role';

/************ Add Foreign Keys to Database ***************/

/************ Foreign Key: fk_profile_security ***************/
ALTER TABLE profile ADD CONSTRAINT fk_profile_security
 FOREIGN KEY (username) REFERENCES security (username);

/************ Foreign Key: fk_record_profile ***************/
ALTER TABLE record ADD CONSTRAINT fk_record_profile
 FOREIGN KEY (profileId) REFERENCES profile (profileId);

After wards, I created JSF Project in NetBeans 6.8 Like this :

Then, I created Hibernate Mappings From DB like this :

By clicking The Finish Button : The hibernate.reveng.xml gets created.

Now, we need to create the Hibernate Mapping Files XML and POJOs

And the result become like this :

So, We now need to Generate the JSF CRUD application like this :

After clicking the Finish button , the project result is the following :

And the result is the following .. after running the application:

I would like to know your opinions and your suggestions, Next I will introduce EJB , Spring Acegi and may be web services.

Hope somebody liked this tutorial.