Bonjour, bonjour!

Je programme une application Web en java avec netbeans et Glassfish.
Avant j'utilisai une connection pools pour gérer ma base de donnée informix :

jdbc/frameWeb

Et on m'a demander d'utiliser "OpenJPA" et la persistence.
Alors tout d'abord Netbeans reconnait ma base de données.

ensuite j'ai créer les unités de persistances (5 en tout).

J'ai reussi a me connecter à la base de donnée:

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
public static int connectToDBServer(String username, String password)
    {
        try
        {
           id=username;
            pass=password;
 
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("FrameAppliWebPU");
            OpenJPAEntityManagerFactory kemf=OpenJPAPersistence.cast(emf);
            OpenJPAConfiguration conf=kemf.getConfiguration();
            DataSource ds=(DataSource)conf.getConnectionFactory();
            conn=ds.getConnection(id,pass);
            return 2;
        }
        catch(SQLException parExc)
        {
            JOptionPane.showMessageDialog(null,parExc.getMessage(),"Erreur de la base de donnee",JOptionPane.ERROR_MESSAGE);
            return 1;
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return 1;
        }
    }//connexion a la base de donnees
Maintenant j'aimerai pouvoir gérer des requetes tel qu'un "select", "insert", "update", "delete"

Je voudrai savoir qu'elle méthode utiliser.
Savoir si j'ai bien paramétrer mon persistence.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
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="FrameAppliWebPU" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>jdbc/frameWeb</jta-data-source>
    <non-jta-data-source>jdbc/frameWeb</non-jta-data-source>
    <properties>
         <property name="openjpa.ConnectionDriverName" value="com.informix.jdbc.IfxDriver"/>
         <property name="openjpa.ConnectionProperties"
            value="PortNumber=1790, ServerName=idsnet, DatabaseName=frameweb, IfxIFXHOST=cocos.frame.fr"/>
         <property name="openjpa.ConnectionFactoryProperties" value="QueryTimeout=5000"/> 
      </properties>
  </persistence-unit>
</persistence>
et savoir comme faire pour que les clé privée de mes tables soient générée automatiquement.

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package Persistence;
 
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
 
/**
 *
 * @author helene
 */
@Entity
@Table(name = "societe")
@NamedQueries({@NamedQuery(name = "Societe.findByIdsoc", query = "SELECT s FROM Societe s WHERE s.idsoc = :idsoc"), @NamedQuery(name = "Societe.findByNom", query = "SELECT s FROM Societe s WHERE s.nom = :nom"), @NamedQuery(name = "Societe.findByAdresse", query = "SELECT s FROM Societe s WHERE s.adresse = :adresse"), @NamedQuery(name = "Societe.findByCp", query = "SELECT s FROM Societe s WHERE s.cp = :cp"), @NamedQuery(name = "Societe.findByVille", query = "SELECT s FROM Societe s WHERE s.ville = :ville"), @NamedQuery(name = "Societe.findByPays", query = "SELECT s FROM Societe s WHERE s.pays = :pays"), @NamedQuery(name = "Societe.findByTelephone", query = "SELECT s FROM Societe s WHERE s.telephone = :telephone"), @NamedQuery(name = "Societe.findByFax", query = "SELECT s FROM Societe s WHERE s.fax = :fax"), @NamedQuery(name = "Societe.findByResp", query = "SELECT s FROM Societe s WHERE s.resp = :resp"), @NamedQuery(name = "Societe.findByCodesociete", query = "SELECT s FROM Societe s WHERE s.codesociete = :codesociete"), @NamedQuery(name = "Societe.findByTiers", query = "SELECT s FROM Societe s WHERE s.tiers = :tiers")})
public class Societe implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "idsoc", nullable = false)
    private Integer idsoc;
    @Column(name = "nom")
    private String nom;
    @Column(name = "adresse")
    private String adresse;
    @Column(name = "cp")
    private Integer cp;
    @Column(name = "ville")
    private String ville;
    @Column(name = "pays")
    private String pays;
    @Column(name = "telephone")
    private String telephone;
    @Column(name = "fax")
    private String fax;
    @Column(name = "resp")
    private String resp;
    @Column(name = "codesociete")
    private Integer codesociete;
    @Column(name = "tiers")
    private String tiers;
    @OneToMany(mappedBy = "idsoc")
    private Collection<Probleme> problemeCollection;
 
    public Societe()
    {
    }
 
    public Societe(Integer idsoc)
    {
        this.idsoc = idsoc;
    }
 
    public Integer getIdsoc()
    {
        return idsoc;
    }
 
    public void setIdsoc(Integer idsoc)
    {
        this.idsoc = idsoc;
    }
 
    public String getNom()
    {
        return nom;
    }
 
    public void setNom(String nom)
    {
        this.nom = nom;
    }
 
    public String getAdresse()
    {
        return adresse;
    }
 
    public void setAdresse(String adresse)
    {
        this.adresse = adresse;
    }
 
    public Integer getCp()
    {
        return cp;
    }
 
    public void setCp(Integer cp)
    {
        this.cp = cp;
    }
 
    public String getVille()
    {
        return ville;
    }
 
    public void setVille(String ville)
    {
        this.ville = ville;
    }
 
    public String getPays()
    {
        return pays;
    }
 
    public void setPays(String pays)
    {
        this.pays = pays;
    }
 
    public String getTelephone()
    {
        return telephone;
    }
 
    public void setTelephone(String telephone)
    {
        this.telephone = telephone;
    }
 
    public String getFax()
    {
        return fax;
    }
 
    public void setFax(String fax)
    {
        this.fax = fax;
    }
 
    public String getResp()
    {
        return resp;
    }
 
    public void setResp(String resp)
    {
        this.resp = resp;
    }
 
    public Integer getCodesociete()
    {
        return codesociete;
    }
 
    public void setCodesociete(Integer codesociete)
    {
        this.codesociete = codesociete;
    }
 
    public String getTiers()
    {
        return tiers;
    }
 
    public void setTiers(String tiers)
    {
        this.tiers = tiers;
    }
 
    public Collection<Probleme> getProblemeCollection()
    {
        return problemeCollection;
    }
 
    public void setProblemeCollection(Collection<Probleme> problemeCollection)
    {
        this.problemeCollection = problemeCollection;
    }
 
    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idsoc != null ? idsoc.hashCode() : 0);
        return hash;
    }
 
    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Societe)) {
            return false;
        }
        Societe other = (Societe) object;
        if ((this.idsoc == null && other.idsoc != null) || (this.idsoc != null && !this.idsoc.equals(other.idsoc))) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString()
    {
        return "Persistence.Societe[idsoc=" + idsoc + "]";
    }
 
}
comme ici avec "idsoc"


Merci d'avance de m'éclairer un peu