CRUD with Spring MVC & Hibernate

2. Update Maven Dependency

For this project we need to add MySQL connector (mysql-connector-java), Spring ORM (spring-orm), Spring transactions (spring-tx), Hibernate core (hibernate-core), and Commons DBPC (commons-dbcp) library. The update pom.xml file is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.munif</groupId>
    <artifactId>bookstore</artifactId>
    <name>BookstoreHibernateWeb</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>

<pre><code>    &amp;lt;!-- Hibernate / JPA --&amp;gt;
    &amp;lt;hibernate.version&amp;gt;4.2.1.Final&amp;lt;/hibernate.version&amp;gt;

&amp;lt;/properties&amp;gt;
&amp;lt;dependencies&amp;gt;
    &amp;lt;!-- Spring --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-context&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.springframework-version}&amp;lt;/version&amp;gt;
        &amp;lt;exclusions&amp;gt;
            &amp;lt;!-- Exclude Commons Logging in favor of SLF4j --&amp;gt;
            &amp;lt;exclusion&amp;gt;
                &amp;lt;groupId&amp;gt;commons-logging&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;commons-logging&amp;lt;/artifactId&amp;gt;
            &amp;lt;/exclusion&amp;gt;
        &amp;lt;/exclusions&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-webmvc&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.springframework-version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-orm&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.springframework-version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-tx&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.springframework-version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- AspectJ --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.aspectj&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;aspectjrt&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.aspectj-version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- Logging --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.slf4j&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;slf4j-api&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.slf4j-version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.slf4j&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jcl-over-slf4j&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.slf4j-version}&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;runtime&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.slf4j&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;slf4j-log4j12&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${org.slf4j-version}&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;runtime&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;log4j&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;log4j&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1.2.15&amp;lt;/version&amp;gt;
        &amp;lt;exclusions&amp;gt;
            &amp;lt;exclusion&amp;gt;
                &amp;lt;groupId&amp;gt;javax.mail&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;mail&amp;lt;/artifactId&amp;gt;
            &amp;lt;/exclusion&amp;gt;
            &amp;lt;exclusion&amp;gt;
                &amp;lt;groupId&amp;gt;javax.jms&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;jms&amp;lt;/artifactId&amp;gt;
            &amp;lt;/exclusion&amp;gt;
            &amp;lt;exclusion&amp;gt;
                &amp;lt;groupId&amp;gt;com.sun.jdmk&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;jmxtools&amp;lt;/artifactId&amp;gt;
            &amp;lt;/exclusion&amp;gt;
            &amp;lt;exclusion&amp;gt;
                &amp;lt;groupId&amp;gt;com.sun.jmx&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;jmxri&amp;lt;/artifactId&amp;gt;
            &amp;lt;/exclusion&amp;gt;
        &amp;lt;/exclusions&amp;gt;
        &amp;lt;scope&amp;gt;runtime&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- @Inject --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;javax.inject&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;javax.inject&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- Servlet --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;servlet-api&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;javax.servlet.jsp&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jsp-api&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.1&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;jstl&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1.2&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- Hibernate --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;hibernate-entitymanager&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${hibernate.version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;hibernate-core&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;${hibernate.version}&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- MySQL Connector --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;mysql&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;mysql-connector-java&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;5.1.25&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- Others --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;commons-dbcp&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;commons-dbcp&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;1.4&amp;lt;/version&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;!-- Test --&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;4.7&amp;lt;/version&amp;gt;
        &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-eclipse-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.9&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;additionalProjectnatures&amp;gt;
                    &amp;lt;projectnature&amp;gt;org.springframework.ide.eclipse.core.springnature&amp;lt;/projectnature&amp;gt;
                &amp;lt;/additionalProjectnatures&amp;gt;
                &amp;lt;additionalBuildcommands&amp;gt;
                    &amp;lt;buildcommand&amp;gt;org.springframework.ide.eclipse.core.springbuilder&amp;lt;/buildcommand&amp;gt;
                &amp;lt;/additionalBuildcommands&amp;gt;
                &amp;lt;downloadSources&amp;gt;true&amp;lt;/downloadSources&amp;gt;
                &amp;lt;downloadJavadocs&amp;gt;true&amp;lt;/downloadJavadocs&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;2.5.1&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;source&amp;gt;1.6&amp;lt;/source&amp;gt;
                &amp;lt;target&amp;gt;1.6&amp;lt;/target&amp;gt;
                &amp;lt;compilerArgument&amp;gt;-Xlint:all&amp;lt;/compilerArgument&amp;gt;
                &amp;lt;showWarnings&amp;gt;true&amp;lt;/showWarnings&amp;gt;
                &amp;lt;showDeprecation&amp;gt;true&amp;lt;/showDeprecation&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;exec-maven-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;1.2.1&amp;lt;/version&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;mainClass&amp;gt;org.test.int1.Main&amp;lt;/mainClass&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;
</code></pre>

&lt;/project&gt;

After updating your pom.xml, run Maven install and update your project.

Advertisements

3 thoughts on “CRUD with Spring MVC & Hibernate

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s