thomas1413
thomas1413

Reputation: 67

Problem with import javax.persistence.EntityManager;

Hey I want to make projects using databases. I've found some tutorials on youtube, but I have problem with Java JPA/Hibernate. Even tho I am following each step I just cant get to import in my class

import javax.persistence.EntityManage

I am using IntelliJ and here is how I am trying to do it. First I create maven project without archetypes. Then in my pom.xml file which for some reason looks different than the one in tutorial.

I am adding dependencies.

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

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

The second one might not be needed, but I am trying everything at this point. At the end my pom.xml file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>BD</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
        </dependency>

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

    </dependencies>
</project>

In my pom file there are no errors. I have also made persistence.xml file, but the problem appears before it matters. I've spent few hours looking for solution and I am so angry at myself that I cant get over such a easy thing, but I have no idea what am I doing wrong. I literally follow tutorial that clearly works.

Upvotes: 0

Views: 5240

Answers (1)

daliborp
daliborp

Reputation: 171

IntelliJ IDEA sometimes needs a little help to refresh dependencies declared in pom.xml:

You can manually re-import dependencies by following procedure:

  1. In the Maven tool window, right-click a linked project.
  2. From the context menu, select Reload project the Reload project icon.

More info is provided in official docs:

Upvotes: 2

Related Questions