5

I'm fairly new to Java/Spring and am trying to put together a simple app which will include some basic CRUD operations and I'd like to use Hibernate for data access.

I'm using Maven as my build tool. My question is: how can I find out which dependencies are required to use Hibernate? For example, I'm using Spring 3.0.6, but how would I know what version of Hibernate to use with that version of Spring? More over, if there are multiple possible Hibernate dependencies, how would I know which ones to include for the functionality I need? So far this seems to be partially reading documentation and partially trial and error.

Is there a definitive way of knowing which Maven dependencies to use with certain version of other dependencies? Any which dependencies to use for particular bits of functionality?

Thanks,

James.

James
  • 273
  • 2
  • 12

4 Answers4

4

I follow these steps when starting to use a new framework:

  1. Go to framework's web site. In your case hibernate web site and try to find latest (or a specific) version. For hibernate it is 3.6.8-Final at the time of writing.
  2. Search for a maven dependency definition on the framework web site. If you can not find any dependency definition, them simply google for "frameworkname _version_ maven dependency" and you'll most probably find necessary definition, as well as the necessary repository information. For example you can find the dependency definition for hibernate on mvnrepository.com and necessary artifact repository information on Hibernate 3.6.8 release page:

    The artifacts have all been published to the JBoss Nexus repository under the org.hibernate groupId at http://repository.jboss.org/nexus/content/groups/public-jboss/

  3. The question of which dependencies are necessary and which are optional depends entirely on the framework to be used. So for example in order to use hibernate, as stated on Hibernate Quick Start Guide:

    hibernate-core: The main artifact, which contains all the Hibernate classes, in packageorg.hibernate. You need these to build applications using the native Hibernate APIs. It includes capabilities for using native Hibernate mapping in hbm.xml files, as well as annotations.

    About compatibility issues (which version of hibernate is compatible with spring 3.0.6), all I can say is you have to read about integration manuals for those frameworks. Since Spring and Hibernate are two exclusively distinct frameworks, I don't think you can find a constant location to look for version compatibility matrix or something like that.

melihcelik
  • 4,531
  • 1
  • 21
  • 25
1

The purpose of Maven is to avoid handling dependencies by hand. Just choose which version of Hibernate to use and include it in your pom; Spring supports many different versions.

If you know what parts of Spring you want to use, just include those parts in your pom; they'll include their own requirements.

Is there a specific module and/or version combination you're having an issue with?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
0

The only way to know for sure that you've got all dependencies is by running your app. Maven resolves for you transitive dependencies so you can quickly detect missing ones by compiling the java code. However, in a web app there are many dependencies that are required in runtime only, so they are not detected at compilation time.

you can find out the dependencies by running mvn dependency:tree and analyze if they are required or not by running mvn dependency:analyze.

Gabriel Belingueres
  • 2,945
  • 1
  • 24
  • 32
0

Taking the newest ones usally works as long as they are stable.

Start with hibernate and spring core, context, tx.

After you added some could you will probably recognize that something else is missing.

Try and error doesn't sound good, but its working pretty well for spring dependencies.

Udo Held
  • 12,314
  • 11
  • 67
  • 93