Bonjour,

Je fais du j2SE.

En fait je veux juste me connecter à la bdd mysql.

J'ai un serveur Glassfish 3 (jai suivi le tuto), mysql installé et bonecp déposé dans le bon dossier.

J'ai crée une DATABASE toto avec une table client :

CREATE TABLE CLIENT(
IDCLIENT INTEGER NOT NULL PRIMARY KEY,
NAME VARCHAR(32) NOT NULL,
) ENGINE = InnoDB;

Apres j ai pris glassfish pour ceci:

"Comme je vous l’ai annoncé un peu plus tôt, Tomcat ne gère pas les EJB de manière native. Et comme vous le savez maintenant, sans EJB pas de JPA. Nous pourrions certes ajouter les jar des différentes solutions dont nous allons avoir besoin pour continuer à travailler sous Tomcat, mais ce n’est pas ce que nous allons faire. Je souhaite en effet profiter de cette occasion pour vous faire travailler sur un autre serveur, un vrai serveur d’applications Java EE cette fois : GlassFish. Pas n’importe quel serveur d’ailleurs : il s’agit du serveur de référence, celui qui implémente à la lettre les spécifications Java EE 6. Rien d'étonnant me direz-vous, puisque c'est Oracle - la maison mère de tout l'écosystème Java - qui édite ce serveur !"

Je ne me suis pas embeté, je me connecte via jdbc en tant que root.

Voici mon fichier Client : (pour JPA)
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
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
 
 
@Entity
public class Client {
 
    @Id
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    private Long idclient;
 
    private String name;
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
}
Mon 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
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
 
public class ClientDao {
    private static final String JPQL_SELECT_PAR_EMAIL = "SELECT u FROM Utilisateur u WHERE u.email=:email";
 
    public static void main(String[] argv) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Toto");
        EntityManager em = emf.createEntityManager();
        Client client = em.find(Client.class, 1);
        if (client != null) {
        System.out.println("Personne.nom=" + client.getName());
        }
        em.close();
        emf.close();
    }
}
Voila mon fichier de persistence :

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
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
 
instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
 
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="Toto">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>Client</class>
    <properties>
        <property name="hibernate.connection.provider_class"
 
value="com.jolbox.bonecp.provider.BoneCPConnectionProvider" />
        <property name="poolName" value="BoneCPPool"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="minConnectionsPerPartition" value="1"/>
        <property name="maxConnectionsPerPartition" value="20"/>
        <property name="acquireIncrement" value="2"/>
        <property name="partitionCount" value="1"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/Toto"/>
        <property name="user" value="root"/>
        <property name="password" value="root"/>
        <property name="idleConnectionTestPeriodInMinutes" value="240"/>
        <property name="idleConnectionTestPeriodInSeconds" value="14400"/>
        <property name="idleMaxAgeInMinutes" value="60"/>
        <property name="idleMaxAgeInSeconds" value="3600"/>
        <property name="connectionTestStatement" value="/* ping *\/ SELECT 1"/>
        <property name="statementsCacheSize" value="0"/>
        <property name="releaseHelperThreads" value="3"/>
        <property name="closeConnectionWatch" value="false"/>
        <property name="logStatementsEnabled" value="false"/>
        <property name="acquireRetryDelayInMs" value="7000"/>
        <property name="lazyInit" value="false"/>
        <property name="transactionRecoveryEnabled" value="false"/>
        <property name="acquireRetryAttempts" value="5"/>
        <property name="disableJMX" value="false"/>
        <property name="queryExecuteTimeLimitInMs" value="0"/>
        <property name="poolAvailabilityThreshold" value="20"/>
        <property name="disableConnectionTracking" value="false"/>
        <property name="connectionTimeoutInMs" value="0"/>
        <property name="closeConnectionWatchTimeoutInMs" value="0"/>
        <property name="statementReleaseHelperThreads" value="0"/>
        <property name="maxConnectionAgeInSeconds" value="0"/>
        <property name="statisticsEnabled" value="false"/>
        <property name="externalAuth" value="false"/>
        <property name="deregisterDriverOnClose" value="false"/>
    </properties>
    </persistence-unit>
</persistence>
Le probleme c'est que ça me retourne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Toto
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at ClientDao.main(ClientDao.java:12)


Ah ! J allais oublier, j'ai aussi le bon bonecp (la version 0.8)

J'aimerais garder une interaction avec bonecp pour gerer le pool

Quelqu'un pourrait m'aider ?

Cordialement.