Bonjour,

Etant débutant en JPA je me forme au travers du livre d'Antonio goncalves JavaEE 6 Glassfish.

J'ai donc effectué un tuto ou deux tables "Cd" et "Artist" sont en relation via une relation @ManyToMany.

J'ai donc préalablement crée mes trois tables en sql à savoir
CD
ARTIST
JND_ART_CD (table de jointure)

J'ai définit mes deux entités à savoir: Artist et Cd et mon fichier Main ArtistCd

Voici l'erreur que j'ai lorsque je souhaite "runé" le programme.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mynewdatabase.sequence' doesn't exist
Error Code: 1146
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
Exception in thread "main" Local Exception Stack: 
	bind => [2 parameters bound]
Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mynewdatabase.sequence' doesn't exist
Error Code: 1146
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
Je pense donc que le problème viens de mon fichier xml de persistance mais malgré de nombreuses recherches et de nombreuses recherches sur le net je bloque, voici le fichier xml:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
<?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="ArtistCdPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>Fiche.Artist</class>
    <class>Fiche.Cd</class>
    <properties>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/MyNewDatabase"/>
      <property name="javax.persistence.jdbc.password" value="******"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    </properties>
  </persistence-unit>
</persistence>
Voici le code du Main:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
package artistcd;
 
import Fiche.Artist;
import Fiche.Cd;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
 
    public static void main(String[] args) {
 
 
    Artist fiche = new Artist();  
    fiche.setLastName("Franck");
    fiche.setFirstName("Moulino");
 
 
    Cd fiche2 = new Cd();
    fiche2.setTitle("Goulou a caracasse");
    fiche2.setPrice(12.8);
    fiche2.setDescription("rock");
 
 
 
    EntityManagerFactory emf  =  Persistence.createEntityManagerFactory("ArtistCdPU");
    EntityManager em = emf.createEntityManager();    
    EntityTransaction tx= em.getTransaction();
 
    Query query = em.createNamedQuery("recherchefranck");
    List <Artist> ListFranck = query.getResultList();
 
    if(ListFranck.isEmpty()){
      tx.begin();
      em.persist(fiche);
      em.persist(fiche2);
      tx.commit();
    }
 
        else{
        System.out.println("La fiche existe dejà");
        }   
    query = em.createNamedQuery("cdartist"); 
    List <Cd> ListCd = query.getResultList();
 
    fiche.setAppearsoncds(ListCd);
 
        for(Cd a: ListCd){
            System.out.println("Les disques rock sont: "+a.getTitle());
            }
 
     em.close();
     emf.close();   
        }
    }
De l'entité Artist:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package Fiche;
 
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
 
 
@Entity
@NamedQuery(name="recherchefranck",query="SELECT a FROM Artist a WHERE a.lastname='Franck'")
public class Artist implements Serializable {
 
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long artist_id;
    private String lastname;
    private String firstname;
//Mise en relation de la Table Artist avec la table Jnd_art_cd
    @ManyToMany
    @JoinTable(name = "jnd_art_cd",
    joinColumns =
    @JoinColumn(name = "artist_fk"),
    inverseJoinColumns =
    @JoinColumn(name = "cd_fk"))
    private List <Cd> appearsoncds;
 
    //Constructeurs   
    public Artist() {
    }
 
    public Artist(Long artist_id, String lastname, String firstname) {
        this.artist_id = artist_id;
        this.lastname = lastname;
        this.firstname = firstname;
    }
 
    // GETTERS AND SETTERS
    public Long getArtist_Id() {
        return artist_id;
    }
 
    public void setArtist_Id(Long id) {
        this.artist_id = artist_id;
    }
 
    public String getFirstName() {
        return firstname;
    }
 
    public void setFirstName(String firstname) {
        this.firstname = firstname;
    }
 
    public String getLastName() {
        return lastname;
    }
 
    public void setLastName(String lastname) {
        this.lastname = lastname;
    }
 
    public void setAppearsoncds(List<Cd> appearsoncds) {
        this.appearsoncds = appearsoncds;
    }
 
 
}
Et de l'entité Cd:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package Fiche;
 
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
 
@Entity
@NamedQuery(name="cdartist",query ="SELECT c FROM Cd c WHERE c.description='rock'")
public class Cd implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long cd_id;
    private String title;
    private Double price;
    private String description;
    //Je map la relation entre les tables
    @ManyToMany (mappedBy="appearsoncds")
    private List<Artist>createdByArtists;
 
    public Cd(){
 
    }
 
    public Cd(String title, Double price, String description) {
        this.title = title;
        this.price = price;
        this.description = description;
    }
 
 
 
    //GETTERS AND SETTERS
    public Long getCd_Id() {
        return cd_id;
    }
 
    public void setCd_Id(Long cd_id) {
        this.cd_id = cd_id;
    }
 
    public String getDescription() {
        return description;
    }
 
    public void setDescription(String description) {
        this.description = description;
    }
 
    public Double getPrice() {
        return price;
    }
 
    public void setPrice(Double price) {
        this.price = price;
    }
 
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
 
}
Avez vous une idée d'ou cette erreur peux provenir? Et comment y remédier?
Merci par avance.