How to get Hibernate + javax.persistence via Maven2 pom.xml

22,147

Declare the JBoss repository:

<project>
  ...
  <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>

And then the following dependency:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.5.6-Final</version>
    </dependency>
    ...
  </dependencies>
  ...
</project>

And that's all your need, the other dependencies will be pulled transitively.

Share:
22,147
Tim
Author by

Tim

still learning :-)

Updated on October 11, 2020

Comments

  • Tim
    Tim over 3 years

    I am a newbie with Maven2 and I write a pom.xml. Now I want to get Hibernate and javax.persistence to resolve this:

    import javax.persistence.Entity;
    ...
    import org.hibernate.annotations.Fetch;
    ...
    

    What needed to be done? I wrote in my pom.xml:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
    

    But I get an error (I already get some other dependencies, but Hibernate does not work):

    11.10.10 13:19:53 MESZ: Refreshing [/testProject/pom.xml]
    11.10.10 13:19:54 MESZ: Missing artifact org.hibernate:hibernate:jar:3.5.6-Final:compile
    11.10.10 13:19:54 MESZ: Maven Builder: AUTO_BUILD 
    11.10.10 13:19:55 MESZ: Maven Builder: AUTO_BUILD
    

    So, what's wrong here? Why it does not know the artifact?

    Thank you in advance & Best Regards.

  • Tim
    Tim over 13 years
    Thank you for your answer, but I get: 11.10.10 13:27:50 MESZ: [WARN] Missing POM for org.hibernate:hibernate-entitymanager:jar:3.5.6-Final 11.10.10 13:27:51 MESZ: Missing artifact org.hibernate:hibernate-entitymanager:jar:3.5.6-Final:compil‌​e
  • Devanshu Mevada
    Devanshu Mevada over 13 years
    @Tim Oh, I was assuming you had the JBoss repository declared. I've updated my answer.
  • Tim
    Tim over 13 years
    Okay, now it works, the javax.persistence.* can be resolved, but not for example the "import org.hibernate.annotations.Fetch;" Sorry, after restarting my workbench, it is resolved!
  • Sean Patrick Floyd
    Sean Patrick Floyd over 13 years
    @Tim you shouldn't mix hibernate annotations with JPA annotations anyway. There's no point in using an open standard like JPA if you're going to add proprietary code. If you want hibernate features that JPA doesn't have, use plain hibernate. But if you use JPA, learn to live with it's limits.
  • Tim
    Tim over 13 years
    Okay, so I do not need javax.persistence.*? I can use it with pure Hibernate?
  • Sean Patrick Floyd
    Sean Patrick Floyd over 13 years
    you can, yes, but then you tie yourself to one persistence provider. I personally prefer to use vendor-neutral jpa code. if you do choose pure hibernate, replace hibernate-entitymanager with hibernate-core in the above pom snippets.
  • stivlo
    stivlo over 12 years
    Apparently now it's not necessary to specify JBoss repository, since the packages have been added to Maven Central