6

I am learning Hibernate (OR Mapping). I am using Maven for project management. However, I am currently reading a Hibernate book by O'Reilly, and they use ANT for their example. So my question is are there any difference between setting up hibernate with ANT and Maven?

Thanks in advance!

James116
  • 163
  • 3
  • I think, this url will be very much useful to you.. http://www.java4s.com/hibernate/hibernate-framework-index/ –  Nov 12 '12 at 03:54

2 Answers2

3

No there is no difference when you setup Hibernate either way. Using maven or ant will only change the way you configure, build, deploy your project.

The way you write Hibernate code will not change in any way if you use Maven or Ant.

In maven pom.xml you will have to add the repository as documented below -

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>        
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.1.Final</version>
            <classifier>tests</classifier>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>      
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.0.1.Final</version>
        </dependency>       
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>

And the following repository will have to be added -

    <repository>
        <id>JBoss</id>
        <name>JBoss Repsitory</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>
Apache Fan
  • 146
  • 4
  • To reduce the size of your Maven pom.xml, just include entity-manager and validator, the rest are internal dependencies from there. – Gary Nov 13 '12 at 09:12
0

If you want to see a complete web application that provides:

  • Hibernate configuration through Spring
  • DAOs with Spring's HibernateTemplate
  • DTOs with JPA annotations (@Column, @OneToOne, @OneToMany, @ManyToOne etc)
  • examples of Hibernate user types for persisting Joda Time and Joda Money

then you might want to refer to the MultiBit Merchant project on GitHub.

It also features examples of RESTful APIs with HAL and uses Dropwizard which may come in useful to you later on when you come to integrate your Hibernate work into a web application. All the code is MIT license so just take it and use it.

Gary
  • 24,420
  • 9
  • 63
  • 108