Maven Hibernate Dependency

In this section, you will learn about maven hibernate dependency.


 

Ads

Tutorials   
How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code
Ads

Maven Hibernate Dependency

In this section, you will learn about maven hibernate dependency.

In the below example, you will learn how to use Maven command to generate a simple Java project and setting up pom.xml to add support for Hibernate and MySQL :

For downloading and installing  Maven click here.

Example

For creating the project inside folder workspace , execute the below command in command prompt :

C:\workspace>mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus
.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.
archetypes:maven-archetype-quickstart:1.0)
...........................................................................
Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/2
4/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44) 15: : 15

..........................................................................

Define value for groupId: : net.roseindia
Define value for artifactId: : HibernateTutorial
Define value for version: 1.0-SNAPSHOT: :
Define value for package: : net.roseindia
Confirm properties configuration:
groupId: net.roseindia
artifactId: HibernateTutorial
version: 1.0-SNAPSHOT
package: net.roseindia
Y: : y

..........................................................................

[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating OldArchetype: maven-archetype-qui
ckstart:RELEASE
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: net.roseindia
[INFO] Parameter: packageName, Value: net.roseindia
[INFO] Parameter: package, Value: net.roseindia
[INFO] Parameter: artifactId, Value: HibernateTutorial
[INFO] Parameter: basedir, Value: C:\workspace
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM
***********************
[INFO] OldArchetype created in dir: C:\workspace\HibernateTutorial
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 minutes 47 seconds
[INFO] Finished at: Sat Apr 07 17:02:23 GMT+05:30 2012
[INFO] Final Memory: 9M/21M
[INFO] ------------------------------------------------------------------------

In workspace folder, you will see the following structure, which is auto generated :

Create folder resources , put Hibernator's XML files inside resource folder  as follows :

Adding dependencies for Hibernate and MySQL in pom.xml

Inside HibernateTutorial folder, you will get pom.xml file, add support for Hibernate and MySQL. Hibernate is required dom4j, commons-logging, commons-collections and cglib as dependency library, add it as follows :

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.roseindia</groupId>
<artifactId>HibernateTutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>HibernateTutorial</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>

<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>3.2.3.GA</version>
</dependency>


<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Hibernate library dependecy end -->

</dependencies>
</project>

Advertisements

Share on Google+Share on Google+

Maven Hibernate Dependency

Posted on: April 20, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Maven Hibernate Dependency  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads