0

Now two days trying to fix this problem. The problem seems to come from the DAO class.

Caused by: projet.helpdesk.dao.DAOException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist

Error Code: 2289
Call: SELECT SEQ_GEN_IDENTITY.NEXTVAL FROM DUAL
Query: ValueReadQuery(sql="SELECT SEQ_GEN_IDENTITY.NEXTVAL FROM DUAL")
    at projet.helpdesk.dao.UserDao.creer(UserDao.java:25)

This is the entity:

    package projet.helpdesk.beans;

import java.sql.Timestamp;
import javax.persistence.*;
@Entity
@Table(name = "Users")
public class Utilisateur {
    @Column(name = "nom")
    private String nom;
    @Column(name = "prenom")
    private String prenom;
    @Column(name = "email")
    private String email;
    @Column(name = "departement")
    private String dept;
    @Column(name = "poste")
    private String poste;
    @Column(name = "agence")
    private String agence;
    @Column(name = "mdp")
    private String mdp;
    @Column(name = "type")
    private String type;
    @Column(name = "date_inscr")
    private Timestamp date_inscr;

    @Id
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    @Column(name = "id_emp")
    private int idemp;
    public String getNom() {
        return nom;
    }
    public void setNom(String nom) {
        this.nom = nom;
    }
    public String getPrenom() {
        return prenom;
    }
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getDept() {
        return dept;
    }
    public void setDept(String dept) {
        this.dept = dept;
    }
    public String getPoste() {
        return poste;
    }
    public void setPoste(String poste) {
        this.poste = poste;
    }
    public String getAgence() {
        return agence;
    }
    public void setAgence(String agence) {
        this.agence = agence;
    }
    public int getIdemp() {
        return idemp;
    }
    public void setIdemp(int id) {
        this.idemp = id;
    }
    public String getMdp() {
        return mdp;
    }
    public void setMdp(String mdp) {
        this.mdp = mdp;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Timestamp getDate_inscr() {
        return date_inscr;
    }
    public void setDate_inscr(Timestamp date_inscr) {
        this.date_inscr = date_inscr;
    }

}

EDIT: Error occurs when executing query. This is the Stacktrace:

Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [SELECT u FROM Users u WHERE u.email=:email]. 
[14, 19] The abstract schema type 'Users' is unknown.
[28, 35] The state field path 'u.email' cannot be resolved to a valid type.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1616)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:456)
    at projet.helpdesk.dao.UserDao.trouver(UserDao.java:32)

The error comes from the method "trouver"

@Stateless
public class UserDao {
    private static final String JPQL_SELECT_PAR_EMAIL = "SELECT u FROM Users u WHERE u.email=:email";
    private static final String PARAM_EMAIL           = "email";

This is the method "trouver"

 public Utilisateur trouver( String email ) throws DAOException {
        Utilisateur utilisateur = null;
        Query requete = em.createQuery( JPQL_SELECT_PAR_EMAIL );
        requete.setParameter( PARAM_EMAIL, email );
        try {
            utilisateur = (Utilisateur) requete.getSingleResult();
        } catch ( NoResultException e ) {
            return null;
        } catch ( Exception e ) {
            throw new DAOException( e );
        }
        return utilisateur;
    }

knowing that the table Users is declared. This is the bean Utilisateur.

@Entity
@Table(name = "Users")
public class Utilisateur {...
TheNorth
  • 57
  • 10
  • "The abstract schema type 'Users' is unknown". Indeed. And you don't have an Entity with that name. Your class is called Utilisateur, and you haven't defined the "entity name", so cannot use the name "Users" in your JPQL. JPQL does NOT use the TABLE name – Neil Stockton Apr 28 '17 at 15:03
  • Can you please develop more? To fix this problem i have to change Users to Utilisateur "bean's name" ? – TheNorth Apr 28 '17 at 15:13
  • Your JPQL cannot be "SELECT u FROM Users u WHERE u.email=:email" when you dont have an entity called "Users"!!! As per the JPA spec. Since your class is called Utilisateur you could do "SELECT u FROM Utilisateur u WHERE u.email=:email", or alternatively you could put `@Entity(name="Users")` on your class. JPQL != SQL, and the table name has no relevance – Neil Stockton Apr 28 '17 at 15:17
  • Thank you, i don't see errors coming from the method find anymore, however still having errors coming from the method creer which includes `em.persist(bean);` ORA error saying table doesnt exist i'm confused. – TheNorth Apr 28 '17 at 15:26
  • Ok definitely fixed, thanks people. – TheNorth Apr 28 '17 at 15:49

1 Answers1

2

The message tells clearly what the problem is:

Internal Exception: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist

sql="SELECT SEQ_GEN_IDENTITY.NEXTVAL FROM DUAL")

The code is trying to read from a database sequence named "SEQ_GEN_IDENTITY", but this one doesn't exist.

I'm not sure why this, you have this in your code:

@GeneratedValue( strategy = GenerationType.IDENTITY )

This should tell JPA that it should use the database identity column to get the ID for the object it wants to persist.

If you don't have a specific reason to use GenerationType.IDENTITY, you should change it to GenerationType.SEQUENCE.

To do that you have to change your class to look like this:

@Id
@GeneratedValue( strategy = GenerationType.SEQUENCE )
@Column(name = "id_emp")
private int idemp;

If you are using EclipseLink (default) you have to create a database sequence named "seq_gen_sequence". If you are using Hibernate you have to create a database sequence named "hibernate_sequence".

See also:

f_puras
  • 2,521
  • 4
  • 33
  • 38
unwichtich
  • 13,712
  • 4
  • 53
  • 66