- Understanding ORM (Object Relational Mapping) concept.
- Connecting Spring MVC applications with Hibernate.
- Create CRUD (create, read, update, delete) operations.
- 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,
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.
Pages: 1 2 3 4 5 6 7 8 9 10
What is Maven?
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information .
Why should I use it?
- Maven is a (automated) build tools. Maven can downloads and installs required jar/library for your project that declared on pom.xml. No need to add library one by one.
How Maven Works?
Based on my comprehension, here is how Maven works.
- Developers declare required jar/library (for example: Spring, Servlet, Hibernate, etc.) on pom.xml.
- Developers using some libraries on their source codes.
- The source codes go to compiling and building phase.
- At the compiling and building phase, the IDE will call the Maven to build the Java project.
- Maven reads required library on pom.xml.
- Maven downloads required library from offline repository, or …
- Maven downloads required library from online repository.
And then Maven will ‘install’ the library into targeted Java project.
- Compiling and building process will produce a Java apps (either .jar or .war).
How can I use add Maven into my project?
On Eclipse based IDE, simply choose new Maven project template to start.
If you are working with Spring MVC in Spring Tool Suite (STS), the project is automatically an Maven project.
Are there any other options?
Yes, definitely. You can choose Ant Builder  or Gradle  in favor of Maven. Both of them are also build tools.
In this article I will show you how to create your first J2EE applications using Spring Framework and Maven build.
Maven is a build tools (or automation tools) for Java project. It is similar with Ant or Gradle. Maven can automatically download the required dependencies for your project.
- Spring Tool Suite (STS) for Java EE (http://spring.io/tools/sts/all).
Please choose the file according to your OS. I prefer to download the archive version because of its portability.
- An internet connection.
For the first time creating a Spring MVC project, internet connection is REQUIRED. You need to download some project templates from Spring repository. Maven also would like to download some dependencies for Spring. Make sure that you have internet connection. If you are behind a proxy, please refer to this tutorial .