views:

31

answers:

2

I have a IDEA project using maven2.

I want to use hibernate + mysql, what dependancies do I need?

+1  A: 

Pasting these dependencies into pom.xml after <depdendencies> should work:

<!-- 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>

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
</dependency>
<!-- Hibernate library dependecy end -->

Shamelessly cloned from http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/ (with the addition of jta as recommended by a commenter)

You may want to tweak the version numbers on the dependencies.

IntelliJ IDEA 9 can find Maven dependencies based on class name. If you start using a class which isn't available in the current dependencies you can get IntelliJ to help find it by using Alt-Enter.

I used this to great effect with a Java-base Subversion hook implementation I am building at work. I was able to get SVNKit and Google Guice dependencies into my project fairly easily this way.

MySQL in your case may be trickier since it is more of a runtime dependency when using Hibernate.

Alain O'Dea
the spring dependencies aren't there - http://blog.springsource.com/2009/12/02/obtaining-spring-3-artifacts-with-maven/
Redlab
Right you are. I read your question but not it's title. What features of Spring are required? There are a lot of components in Spring and you may not need them all.
Alain O'Dea
These dependencies are really outdated, I don't recommend using them (Hibernate is using SLF4J for some time now).
Pascal Thivent
+1  A: 

first of all, I separate the versions from the artifacts:

<properties>
    <spring.version>3.0.3.RELEASE</spring.version>
    <hibernate.version>3.5.3-Final</hibernate.version>
    <mysql.version>5.1.13</mysql.version>
    <junit.version>4.7</junit.version>
</properties>

then I reference them like this:

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
        <!-- perhaps using scope = provided, as this will often
         be present on the app server -->
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <!-- or hibernate-entitymanager if you use jpa -->
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

That way you keep the versions all in one place and can easily update them, especially if you reference e.g. multiple spring artifacts.

BTW: these should be the current versions, but you can always look up current versions using MvnRepository.com

seanizer