Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

package javax.persistence does not exist

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to use the persistance package, but I got an error:



package javax.persistence does not exist

I have added the JPA dependency into my POM file, I really tried everything, what could be wrong?
Danielle
 
 
Marshal
Posts: 74359
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That package isn't part of the standard API. How did you download it? How did you add its location to the CLASSPATH?
 
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show us your POM.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought adding the dependency is enough:

 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My POM is:

 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried building your project yet? When you add a dependency to your POM, it doesn't immediately become available to the compiler. Maven must download the dependencies first, which it will do if you build it the first time.
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a sidenote, you should probably remove your dependency on spring-security-config. The version you depend on is ancient, and conflicts with the version that is a transitive dependency through spring-boot-starter-security.

You also have a lot of dependencies that you probably don't need at compile-time. Make them into runtime dependencies.
 
Saloon Keeper
Posts: 24536
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javax.persistence API classes are part of the JEE API package. I did some chasing down my favorite project and I actually can't tell what's pulling it in for me, although at a guess, hibernate.entitymanager.

Incidentally, if that postgresql dependency is supposed to pull int the postgresql driver jar, DON'T DO THAT!!! A well-designed JEE webapp doesn't include the database driver. It gets it from the web application server, preferably via a JDBC Connection Pool.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:The javax.persistence API classes are part of the JEE API package. I did some chasing down my favorite project and I actually can't tell what's pulling it in for me, although at a guess, hibernate.entitymanager.

Incidentally, if that postgresql dependency is supposed to pull int the postgresql driver jar, DON'T DO THAT!!! A well-designed JEE webapp doesn't include the database driver. It gets it from the web application server, preferably via a JDBC Connection Pool.



I just tried that, now I get the erroe error: package org.springframework.security.core does not exist
import org.springframework.security.core.Authentication;

 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That shouldn't have anything to do with Tim's suggestion, as Spring Security and PostgreSQL don't have anything to do with each other.

Please show us your new POM.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my new POM:

 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You gave the persistence API the 'runtime' scope. Runtime dependencies are used at runtime only. You need the persistence API at compile time.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this example https://grokonez.com/spring-framework/spring-security/use-spring-security-jdbc-authentication-postgresql-spring-boot

Maybe it is just a wrong example ....
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you figure? The page you linked to doesn't mention JPA or Hibernate.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Danielle Mertens wrote:

Tim Holloway wrote:The javax.persistence API classes are part of the JEE API package. I did some chasing down my favorite project and I actually can't tell what's pulling it in for me, although at a guess, hibernate.entitymanager.

Incidentally, if that postgresql dependency is supposed to pull int the postgresql driver jar, DON'T DO THAT!!! A well-designed JEE webapp doesn't include the database driver. It gets it from the web application server, preferably via a JDBC Connection Pool.





No this is based on a JDBC Connection Pool, as suggested.
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What persistence API (JDBC, JPA) do you want to use in your code, and what implementation or DBMS (PostgreSQL, Hibernate, H2) do you want to use at runtime?
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use JDBC and PostgreSQL to create a login authentication page. I am working with Spring Boot.
Danielle
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you don't need the JPA and H2 dependencies.

You DO need the PostgreSQL dependency, because your application will be embedded in a Spring Boot container, so you need to tell it what drivers to use. It needs to be a runtime dependency though, because drivers are only used at runtime. You should not write code that uses the driver directly. The JDBC API needs to be a compile-time dependency though, because you will want to write code that uses it.

For new applications, rely on dependencies that have a group ID that starts with jakarta instead of javax. Jakarta is the new name of Java EE, and new versions of dependencies will be available under the jakarta identifier.
 
Tim Holloway
Saloon Keeper
Posts: 24536
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Then you don't need the JPA and H2 dependencies.

You DO need the PostgreSQL dependency, because your application will be embedded in a Spring Boot container, so you need to tell it what drivers to use. It needs to be a runtime dependency though, because drivers are only used at runtime. You should not write code that uses the driver directly. The JDBC API needs to be a compile-time dependency though, because you will want to write code that uses it.

For new applications, rely on dependencies that have a group ID that starts with jakarta instead of javax. Jakarta is the new name of Java EE, and new versions of dependencies will be available under the jakarta identifier.



A little clarification here.

You have an unusual situation with Spring Boot because a Spring Boot application has two primary classpaths. One is for the webapp server (embedded Tomcat) and one is for the web appllication itself.  The distinction is important. The PostgreSQL Driver jar MUST NOT be placed in the webapp's WEB-INF/lib directory, it must be placed in the Tomcat lib directory.

At this point, my knowledge runs out, since I've never actually sat down and used Maven to build a Spring Boot app. But you will have to configure the POM and/or Spring Boot config files to make sure that that's what happens.

Reverting to the javax.persistence problem, however, that's part of JPA and in Tomcat, JPA is not built into the server like it is with full-stack servers like WebSphere and Wildfly. So you'd be including that in the libraries in WEB-INF/lib. And JPA is not needed for Spring Security as far as I know or would expect. JPA is for application database logic, But JPA or no JPA. the location of the PostgreSQL driver should never be in WEB-INF/lib.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it must be a problem on my PC, i asked someone else to compile the code and it didn't show any errors .....
Danielle
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show us the Maven output when you try to build the project.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume it is this one:

 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or this one:

 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Maven, the application builds just fine. What problem are you experiencing exactly?
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I did the following actions but they all failed.

- Invalidated cache
- run mvn clean package or mvn clean package in terminal
- Marked to 'autoload snapshots' in Intellij's maven configuration
- Syncornize or Reimport
- Delete all the IntellJ related files like .idea and reimport project
- remove all the dependency files and then run mvn clean package
- Switch Java version or use embedded Java in IntellJ
- run mvn idea:idea

The last thing I did: Delete the .idea and .iml in the project, delete all the dependency files and then delete the IntellJ from the computer. After reinstalled the IntellJ my project still not built successfully.
Danielle





 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you're using JPA after all, and not just JDBC...
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. beacuse JDBC  gave me even more errors.
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going about this the wrong way. When you encounter an error the solution is not to immediately jump ship and try something completely different. You must first try to understand the error, so you can figure out how to fix it, or to make an informed decision that using a different solution is going to be better.

Anyway, if you're going to use JPA then obviously you need to add the JPA dependency back to your POM.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know, but in both options I run into the same problem, it only works if I change the dependencies in Gradle.
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Gradle and Maven in the same project?
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I am using it fot the gradle sync.
 
Stephan van Hulst
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why?

Maven and Gradle are two different build tools. Using both of them in the same project is bound to lead to confusion and bugs.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea :/ I messed it up somewhere. I just started programming and working with Spring boot is not easy for me. I will try to deactivate it.

Thanks for the help anyway!  
 
Tim Holloway
Saloon Keeper
Posts: 24536
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't feel bad. Spring boot is both a webapp server and a webapp rolled into one, which means it's about 3 times as complicated as learning just one of them.

Fortunately, it's a popular technology with a least one good book on the subject and lots of support.
 
Danielle Mertens
Greenhorn
Posts: 24
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out, I put all dependencies in Gradle and I could use all packages, so all errors disappeared.  
 
reply
    Bookmark Topic Watch Topic
  • New Topic