What are the Maven dependencies to use hibernate, hibernate annotations, and ehcache?

前端 未结 3 1285
旧时难觅i
旧时难觅i 2021-01-30 23:46

I would like to update my Maven pom.xml with the latest hibernate, hibernate-annotations, and ehcache dependencies.

I read the hibernate download page and the ehcache do

相关标签:
3条回答
  • 2021-01-31 00:21

    You can go by this pom.xml if you are integrating Spring 3 with hibernate 3

    <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    </properties>
    
    <dependencies>
        <!-- Core utilities used by other modules. Define this if you use Spring 
            Utility APIs (org.springframework.core.*/org.springframework.util.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Expression Language (depends on spring-core) Define this if you use 
            Spring Expression APIs (org.springframework.expression.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define 
            this if you use Spring Bean APIs (org.springframework.beans.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Aspect Oriented Programming (AOP) Framework (depends on spring-core, 
            spring-beans) Define this if you use Spring AOP APIs (org.springframework.aop.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Application Context (depends on spring-core, spring-expression, spring-aop, 
            spring-beans) This is the central artifact for Spring's Dependency Injection 
            Container and is generally always defined -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Various Application Context utilities, including EhCache, JavaMail, 
            Quartz, and Freemarker integration Define this if you need any of these integrations -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Transaction Management Abstraction (depends on spring-core, spring-beans, 
            spring-aop, spring-context) Define this if you use Spring Transactions or 
            DAO Exception Hierarchy (org.springframework.transaction.*/org.springframework.dao.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
            spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, 
            and iBatis. (depends on spring-core, spring-beans, spring-context, spring-tx) 
            Define this if you need ORM (org.springframework.orm.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB, 
            JiBX, Castor, XStream, and XML Beans. (depends on spring-core, spring-beans, 
            spring-context) Define this if you need OXM (org.springframework.oxm.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Web application development utilities applicable to both Servlet and 
            Portlet Environments (depends on spring-core, spring-beans, spring-context) 
            Define this if you use Spring MVC, or wish to use Struts, JSF, or another 
            web framework with Spring (org.springframework.web.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Spring MVC for Servlet Environments (depends on spring-core, spring-beans, 
            spring-context, spring-web) Define this if you use Spring MVC with a Servlet 
            Container such as Apache Tomcat (org.springframework.web.servlet.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Spring MVC for Portlet Environments (depends on spring-core, spring-beans, 
            spring-context, spring-web) Define this if you use Spring MVC with a Portlet 
            Container (org.springframework.web.portlet.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    
        <!-- Support for testing Spring applications with tools such as JUnit and 
            TestNG This artifact is generally always defined with a 'test' scope for 
            the integration testing framework and unit testing stubs -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>
    
    
        <!-- Hibernate resources -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.3.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.1.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.2.GA</version>
        </dependency>
        <!-- EhCache -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
        </dependency>
    
    
        <!-- Taglibs -->
    
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>20030825.184428</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>20030825.183949</version>
        </dependency>
    
        <!-- Log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
            <type>jar</type>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
    
    
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    

    And if you want different versions of hibernate you can check here

    0 讨论(0)
  • 2021-01-31 00:26
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.2.2.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2021-01-31 00:30

    If you really mean the ultimate versions of hibernate-annotations (and not hibernate-entitymanager) and ehcache, then you'll need the following:

    <project>
      ...
      <dependencies>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>3.6.0.Final</version>
        </dependency>
        <dependency>
           <groupId>net.sf.ehcache</groupId>
           <artifactId>ehcache-core</artifactId>
           <version>2.2.0</version>
       </dependency>
       ...
      </dependencies>
    
      <repositories>
        <repository>
          <id>repository.jboss.org-public</id>
          <name>JBoss repository</name>
          <url>https://repository.jboss.org/nexus/content/groups/public</url>
        </repository>
      </repositories>
      ...
    </project>
    

    As of Hibernate 3.6, JDK 1.4 support has been dropped and the Hibernate Annotations have been merged back into Core.

    I you meant Hibernate EntityManager, then replace hibernate-core by hibernate-entitymanager in the above snippet.

    Regarding EHCache, ehcache-core should provide everything you need (including implementations of the "new" Hibernate 3.3/3.5 caching SPI with its CacheRegionFactory). So, as documented:

    Setting Ehcache as the Hibernate Second Level Cache

    Hibernate 3.3 and higher

    ATTENTION HIBERNATE 3.2 USERS

    Make sure to note the change to BOTH the property name and value.

    Use:

    <property name="hibernate.cache.region.factory_class">
              net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
    

    for instance creation, or

    <property name="hibernate.cache.region.factory_class">
              net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</property>
    

    to force Hibernate to use a singleton of Ehcache CacheManager.


    Follow-up: To answer your update:

    sl4j threw errors, which went away by adding (...)

    Well, I can't guess what logging framework you're using, providing the binding of your choice was left as an exercise for the reader :)

    There are many instances of this warning (...)

    I get only one WARNING when running in a non JTA environment. If that's your case (a non JTA environment), I would consider the WARNING as normal. If that's not your case, have a look at the documentation about JTA.

    Additionally, this error makes everything fail

    This is somehow a different question (but it looks like the SessionFactory fails to initialize properly, activate logging to see why) and I suggest to post a new spring specific question.

    0 讨论(0)
提交回复
热议问题