Goals
- Understanding ORM (Object Relational Mapping) concept.
- Connecting Spring MVC applications with Hibernate.
- Create CRUD (create, read, update, delete) operations.
Requirement
- Spring MVC project
- MySQL server for database
- Internet connections
This tutorial consists of quite long steps. Make sure that you follow every step carefully.
1. Define your database
In this example, I will use 2 tables shown below.
There is one-to-many relationship between two tables (Category to Product).
Here is the SQL for creating tables above
CREATE TABLE <code>category</code> ( <code>categoryId</code> int(11) NOT NULL AUTO_INCREMENT, <code>categoryName</code> varchar(45) DEFAULT NULL, <code>categoryDescription</code> text, PRIMARY KEY (<code>categoryId</code>) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; CREATE TABLE <code>product</code> ( <code>productId</code> int(11) NOT NULL AUTO_INCREMENT, <code>productName</code> varchar(45) NOT NULL, <code>productStock</code> int(11) NOT NULL, <code>productPrice</code> float NOT NULL, <code>productDescription</code> text NOT NULL, <code>categoryId</code> int(11) NOT NULL, PRIMARY KEY (<code>productId</code>,<code>categoryId</code>), KEY <code>fk_Product_Category_idx</code> (<code>categoryId</code>), CONSTRAINT <code>fk_Product_Category</code> FOREIGN KEY (<code>categoryId</code>) REFERENCES <code>category</code> (<code>categoryId</code>) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
If you are already have database, you can also try with your own tables.
pak error pak
how to download source code??
how to download source code?????