开发者

What maven artifacts do I need for spring hibernate and mysql support?

开发者 https://www.devze.com 2023-01-07 11:55 出处:网络
I have a IDEA project using maven2. I want to use hibernate + mysql, what dependancies do 开发者_运维百科I need?first of all, I separate the versions from the artifacts:

I have a IDEA project using maven2.

I want to use hibernate + mysql, what dependancies do 开发者_运维百科I need?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号