user3667111
user3667111

Reputation: 631

Spring Boot Project - Issue with writing JPQL (Intellij)

So I have setup a spring boot project with which I'd like to create some specific queries.

Very simple, I just want to execute a select statement:

public class UserRepositoryCustomImpl implements UserRepositoryCustom {

    @PersistenceContext
    private EntityManager entityManager;


    public User findUserByEmail(String email) {
        Query nativeQuery = entityManager.createQuery("select e from User");
        nativeQuery.getFirstResult();
        return new User();
    }

}

In Intellij, when I hover over User it says cannot resolve symbol for User, I've had a google and most of the answers say you need to use the name of the entity, which of course I did:

@Entity(name = "PG_user")
public class User extends AbstractEntity {

    @Column
    private String email;

    @Column
    private String password;

    public User(){}

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Here is my POM also, if this helps:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>0.3.5</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.2.jre8</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.webjars.bower/angular-bootstrap-contextmenu -->
        <dependency>
            <groupId>org.webjars.bower</groupId>
            <artifactId>angular-bootstrap-contextmenu</artifactId>
            <version>0.9.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-crypto -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-crypto</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


    </dependencies>

Upvotes: 0

Views: 41

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36163

But the name of your entity is PG_user

@Entity(name = "PG_user")
public class User extends AbstractEntity {

The name attribute defines the name of the entity that you must use for querying.

But I assume you want to set the name of the table.

That would be

@Table(name = "PG_user")
@Entity
public class User extends AbstractEntity {

Upvotes: 4

Related Questions