Table cannot be resolved jpa

3.3k Views Asked by At

I have a problem on my entity I put all the annotations and also I configured my file persistence.xml so that it generates a table automatically from the entity but I always get an error in the line @Entity that the table can not be resolved.

Here is my Entity :

package org.planetjpa;

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

import java.util.Date;

@Entity
public class Reservationscene implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="id_res_scene")
private Integer idResScene;

@Temporal(TemporalType.TIMESTAMP)
@Column(name="date_reserv_scene")
private Date dateReservScene;

@ManyToOne
    @JoinColumn(name="scene_id")
private Scences scene_reserve;

@ManyToOne
    @JoinColumn(name="user_c_id")
private User user_courant;

public Scences getScene_reserve() {
    return scene_reserve;
}

public void setScene_reserve(Scences scene_reserve) {
    this.scene_reserve = scene_reserve;
}

public User getUser_courant() {
    return user_courant;
}

public void setUser_courant(User user_courant) {
    this.user_courant = user_courant;
}

public Reservationscene() {
}

public int getIdResScene() {
    return this.idResScene;
}

public void setIdResScene(int idResScene) {
    this.idResScene = idResScene;
}

public Date getDateReservScene() {
    return this.dateReservScene;
}

public void setDateReservScene(Date dateReservScene) {
    this.dateReservScene = dateReservScene;
}

}

Scences Entity:

package org.planetjpa;

import java.io.Serializable;
import java.util.ArrayList;

import javax.persistence.*;


@Entity
@Table(name = "scencesnational")
public class Scences implements Serializable {


@Id@Column(name="Id")
private int id_scene;
@Column(name="NOM")
private String nom_scenes;
@Column(name="Addresse")
private String adresse_scenes;
@Column(name = "`ADRESSE 2`")
private String boite_postale;
@Column(name="CP")
private String code_postale;
@Column(name="Surface")
private double surface_scence;
@Column(name="Type")
private String type_scene;
@Column(name="Capacité")
private int capacite_scene;
@Column(name="`Prix réservation`")
private double prix_scene;
private static final long serialVersionUID = 1L;


@OneToMany(mappedBy="scene_reserve")        
private ArrayList<Reservationscene> liste_reserv_scenes;

public Scences() {
    super();
}

public int getId_scene() {
    return id_scene;
}

public void setId_scene(int id_scene) {
    this.id_scene = id_scene;
}

public String getNom_scenes() {
    return nom_scenes;
}

public void setNom_scenes(String nom_scenes) {
    this.nom_scenes = nom_scenes;
}

public String getAdresse_scenes() {
    return adresse_scenes;
}

public void setAdresse_scenes(String adresse_scenes) {
    this.adresse_scenes = adresse_scenes;
}

public String getBoite_postale() {
    return boite_postale;
}

public void setBoite_postale(String boite_postale) {
    this.boite_postale = boite_postale;
}

public String getCode_postale() {
    return code_postale;
}

public void setCode_postale(String code_postale) {
    this.code_postale = code_postale;
}

public double getSurface_scence() {
    return surface_scence;
}

public void setSurface_scence(double surface_scence) {
    this.surface_scence = surface_scence;
}

public String getType_scene() {
    return type_scene;
}

public void setType_scene(String type_scene) {
    this.type_scene = type_scene;
}

public int getCapacite_scene() {
    return capacite_scene;
}

public void setCapacite_scene(int capacite_scene) {
    this.capacite_scene = capacite_scene;
}

public double getPrix_scene() {
    return prix_scene;
}

public void setPrix_scene(double prix_scene) {
    this.prix_scene = prix_scene;
}

}

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence   http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="projetjsf">



    <class>org.planetjpa.Films</class>
    <class>org.planetjpa.Lieux</class>
    <class>org.planetjpa.Reservationscene</class>
    <class>org.planetjpa.Scences</class>
    <class>org.planetjpa.User</class>



<properties>

  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/projetjsf"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.password" value="amine1993"/>
  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
  <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
     <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

    </properties>

</persistence-unit>
</persistence>

When i try to generate table from the entity in JPA tools, i obtain this error :

Exception in thread "main" javax.persistence.PersistenceException:    [PersistenceUnit: projetjsf] Unable to build EntityManagerFactory
 at   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.buildEntityManagerFactory(Main.java:94)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:80)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: org.planetjpa.Scences.liste_reserv_scenes
at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:321)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1693)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:765)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:684)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3406)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3360)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1334)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
... 6 more

Scenes.java :

package org.planetjpa;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Scences
*
*/
@Entity
@Table(name = "scencesnational")
public class Scences implements Serializable {


@Id@Column(name="Id")
private int id_scene;
@Column(name="NOM")
private String nom_scenes;
@Column(name="Addresse")
private String adresse_scenes;
@Column(name = "`ADRESSE 2`")
private String boite_postale;
@Column(name="CP")
private String code_postale;
@Column(name="Surface")
private double surface_scence;
@Column(name="Type")
private String type_scene;
@Column(name="Capacité")
private int capacite_scene;
@Column(name="`Prix réservation`")
private double prix_scene;
private static final long serialVersionUID = 1L;


@OneToMany(mappedBy="scene_reserve")        
private List<Reservationscene> liste_reserv_scenes;

public Scences() {
    super();
}

public int getId_scene() {
    return id_scene;
}

public void setId_scene(int id_scene) {
    this.id_scene = id_scene;
}

public String getNom_scenes() {
    return nom_scenes;
}

public void setNom_scenes(String nom_scenes) {
    this.nom_scenes = nom_scenes;
}

public String getAdresse_scenes() {
    return adresse_scenes;
}

public void setAdresse_scenes(String adresse_scenes) {
    this.adresse_scenes = adresse_scenes;
}

public String getBoite_postale() {
    return boite_postale;
}

public void setBoite_postale(String boite_postale) {
    this.boite_postale = boite_postale;
}

public String getCode_postale() {
    return code_postale;
}

public void setCode_postale(String code_postale) {
    this.code_postale = code_postale;
}

public double getSurface_scence() {
    return surface_scence;
}

public void setSurface_scence(double surface_scence) {
    this.surface_scence = surface_scence;
}

public String getType_scene() {
    return type_scene;
}

public void setType_scene(String type_scene) {
    this.type_scene = type_scene;
}

public int getCapacite_scene() {
    return capacite_scene;
}

public void setCapacite_scene(int capacite_scene) {
    this.capacite_scene = capacite_scene;
}

public double getPrix_scene() {
    return prix_scene;
}

public void setPrix_scene(double prix_scene) {
    this.prix_scene = prix_scene;
}

}
1

There are 1 best solutions below

3
On

Looks like this question has already been asked here. The type of the collection should be an interface, instead of an implementation.

In Scenes.java change the type from ArrayList to List or any of the collection interfaces like Set, Collection etc.

@OneToMany(mappedBy = "scene_reserve")
    private List<Reservationscene> liste_reserv_scenes = new ArrayList<>();