maven compile errors when i'm trying to map entity to table in postgresql

8.6k views Asked by At

I need your help to map entity to table using PostgresSQL database , in fact what causes this error is that I tried to map an entity to a table, unfortunately maven cause this problem that I could not identify, so i have to use code first aproach to map this entity to table in postgresql using jpa , persistance.xml and jboss wildfly. Thanks in advance for your support.

package testdb;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the "HAHA" database table.
 * 
 */
@Entity
@Table(name="Ha_ha", schema="public")
public class Haha implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="ID_HAHA")
    private long idHaha;

    @Column(name="DESIGNATION")
    private String designation;

    public Haha() {
    }

    public long getIdHaha() {
        return this.idHaha;
    }

    public void setIdHaha(long idHaha) {
        this.idHaha = idHaha;
    }

    public String getDesignation() {
        return this.designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

}

And here's an example of error message, exactly as output by maven:

[ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[4,1] package javax.persistence does not exist
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[11,2] cannot find symbol
      symbol: class Entity
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[12,2] cannot find symbol
      symbol: class Table
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[16,10] cannot find symbol
      symbol:   class Id
      location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[17,10] cannot find symbol
      symbol:   class Column
      location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[20,10] cannot find symbol
      symbol:   class Column
      location: class testdb.Haha
    [INFO] 6 errors 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.759 s
    [INFO] Finished at: 2017-11-19T02:12:34+01:00
    [INFO] Final Memory: 17M/211M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project testdb: Compilation failure: Compilation failure:
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[4,1] package javax.persistence does not exist
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[11,2] cannot find symbol
    [ERROR] symbol: class Entity
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[12,2] cannot find symbol
    [ERROR] symbol: class Table
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[16,10] cannot find symbol
    [ERROR] symbol:   class Id
    [ERROR] location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[17,10] cannot find symbol
    [ERROR] symbol:   class Column
    [ERROR] location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[20,10] cannot find symbol
    [ERROR] symbol:   class Column
    [ERROR] location: class testdb.Haha
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
1

There are 1 answers

2
Drew Wills On BEST ANSWER

It looks like you need to add this dependency to your Maven project.

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