Writing Maven Dependency for javax.persistence
Asked Answered
P

5

29

Can someone help me write the dependency for javax.persistence. I have googled it but nothing worked.

I bumped into this page that gives some details on how to write the dependency, but yet i am unable to write it. Can someone help me out?

Pseudocarp answered 23/11, 2011 at 13:35 Comment(0)
D
44

This is the one for javax.persistence:

<dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>persistence-api</artifactId>
   <version>1.0.2</version>
   <scope>provided</scope>
</dependency>

and this is for the whole Java EE 6 stack:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>6.0</version>
   <scope>provided</scope>
</dependency>

Edit
Note that I specified a provided scope here, which means that your dependency is available at compile- and test-time, but will not be packaged into your artifacts. This is usually needed if you want to deploy your artifacts in an application server, since they provide their own implementation of the api.

Downes answered 23/11, 2011 at 13:41 Comment(3)
So you recommend that i use the 2nd optionPseudocarp
Yes, if you would like to use other features of the JEE stack - like EJB or Servlets for example. If you are only interested in persistence, use the first one. :)Downes
Thanks! But I am interesting how one could find the answer by himself? Without copypasting from Google/SO...Dufresne
F
5

And add this dependency in your pom.xml:

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>

That "Coping with Sun JARs" page might be a little outdated, this JAR is available in the Maven Central Repository

Fare answered 23/11, 2011 at 13:40 Comment(0)
R
1

Updated link: https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2 is here.

and the maven dependency is as below:

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
Ramsden answered 1/12, 2022 at 4:35 Comment(2)
This does not works for me.Monger
@Monger what's the error you are facing now?Ramsden
A
0

For the latest versions javax.persistance is not working instead of that we can use jakarta.persistence to create an entity or resolve the error Cannot resolve symbol 'Entity'. For that need to add the dependency

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.6.Final</version>
            <type>pom</type>
        </dependency>
Acanthus answered 24/1, 2023 at 5:11 Comment(1)
i can get neither jakarta.persistence.* nor javax.persistence.* working. Somebody keeps playing musical chairs with this library. I understand "javax" had to be dropped due to Oracle trademark. But, the latest versions of jakarta.persistence-api don't have what I need.Conscript
I
0

I guess you might have resolved the issue by now. Nevertheless I had the same issue and fixed it right clicking on pom.xml -> maven -> reload project.

Isborne answered 1/5 at 5:29 Comment(1)
right clicking on pom.xml Are you referring to the IDE that you are using?Willettawillette

© 2022 - 2024 — McMap. All rights reserved.