IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

Problème de doublons


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut Problème de doublons
    Bonjour,

    j'ai un soucis de doublon sur lequel je me casse les dents. Pour vous situer le contexte, j'ai un base mal entretenue que je doit partiellement transférer dans une nouvelle base. Cette base est une base contenant des clients. Le soucis est que je me retrouve avec l'erreur suivante (j'ai mis des étoile à la place de l'Id, vous comprendrai) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Exception in thread "main" javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.redware.redorg.gestionclient.entities.Mobile#** ** ** ** **
    De plus, quand j'ôte la partie téléphone du mapping, j'ai des violation de contrainte d'unicité sur tous les objets qui en déclare... Je vous passe le code :

    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
     
    public class TransfertDAO {
     
    	private EntityManager cible;
    	private Connection con;
     
    	public void init() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		cible = Persistence
    				.createEntityManagerFactory("MaPU")
    				.createEntityManager();
    	}
     
    	public void begin() {
    		try {
    			con = DriverManager.getConnection(
    					"jdbc:mysql://ipserveur/basedorigine", "login", "password");
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		cible.getTransaction().begin();
    	}
     
    	public void transfertCSO() throws SQLException {
     
    		cible.flush();
    		int count = 0;
    		PreparedStatement st = con
    				.prepareStatement("SELECT Fonction.*, Organisation.*, Interlocuteur.* FROM Organisation RIGHT JOIN (Interlocuteur RIGHT JOIN (Fonction RIGHT JOIN Int_Org_Fon ON Fonction.id_fonction = Int_Org_Fon.ID_Fon) ON Interlocuteur.ID_Interlocuteur = Int_Org_Fon.ID_Int) ON Organisation.Id_Organisation = Int_Org_Fon.ID_Org WHERE ((Int_Org_Fon.TYPE) ='ENT') AND Interlocuteur.nom not in (SELECT Interlocuteur.nom From Interlocuteur WHERE Interlocuteur.nom='aucun') ORDER BY Organisation.nom_org, Interlocuteur.nom");
    		ResultSet rs = st.executeQuery();
    		while (rs.next()) {
    			count++;
     
    			Lieu lieu = transfertLieu(rs);
    			Entreprise entreprise = transfertEntreprise(rs, lieu);
    			Contact contact = transfertContact(rs);
    			Salarie salarie = transfertSalarie(rs);
    			transfertEmail(rs, contact);
    			transfertMobile(rs, "mobile", contact);
    			Set<Lignefixe> lignesfixes = transfertFixes(rs, contact);
     
    			ContactStatutOrga cso = new ContactStatutOrga(contact, entreprise, salarie, true);
    			for(Lignefixe lf:lignesfixes){
    				lf.setCso(cso);
    				if(!cible.contains(lf)){
    					//cible.merge(lf);
    					//cible.persist(lf);
    				}
    			}
    			try {
    				if(!cible.contains(cso)){
    					cible.merge(cso);
    					cible.persist(cso); //ICI L'ERREUR DE DOUBLE ID
    				}
    			} catch (EntityExistsException e) {
    				System.out.println("erreur sur "+cso.getContact().getNom());
    				//System.out.println(cible.find(Mobile.class, e.getLocalizedMessage().split("#")[1].replaceAll("]", "")).toString());
    				e.printStackTrace();
    				break;
    			}
    		}
    		System.out.println(count+" cso persistés");
    	}
     
    	private Set<Lignefixe> transfertFixes(ResultSet rs, Contact contact)
    			throws SQLException {
    		String[] prop = new String[] { "Interlocuteur", "Organisation" };
    		String[] type = new String[] { "tel", "fax" };
    		Set<Lignefixe> lignes = new HashSet<Lignefixe>();
    		for (int i = 0; i < prop.length; i++) {
    			for (int j = 0; j < type.length; j++) {
    				Lignefixe lf = transfertLigne(prop[i], type[j], rs, contact);
    				if (lf != null) {
    					lignes.add(lf);
    				}
    			}
    		}
    		return lignes;
    	}
     
    	private Lignefixe transfertLigne(String proprietaire, String type,
    			ResultSet rs, Contact contact) throws SQLException {
    		Lignefixe lf = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(proprietaire);
    		sb.append('.');
    		sb.append(type);
    		String numeroFixe = rs.getString(sb.toString());
    		if (numeroFixe != null&&numeroFixe.length()>8) {
    			numeroFixe.trim();
    			numeroFixe.replaceAll(" ", "");
    			numeroFixe.replaceAll(".", "");
    			if ((numeroFixe.startsWith("06") || numeroFixe.startsWith("07"))) {
    				transfertMobile(rs, sb.toString(), contact);
    			} else {
    				lf = new Lignefixe();
    				lf.setNumero(numeroFixe);
    				lf.setTypeligne(type);
    			}
    		}
    		return lf;
    	}
     
    	private Mobile transfertMobile(ResultSet rs, String type, Contact contact)
    			throws SQLException {
    		String numeroMobile = rs.getString(type);
    		Mobile mobile = null;
    		if (numeroMobile != null&&numeroMobile.length()>8) {
    			numeroMobile.trim();
    			numeroMobile.replaceAll(" ", "");
    			numeroMobile.replaceAll(".", "");
    			mobile = new Mobile(numeroMobile, contact);
    			if (!cible.contains(mobile)) {
    				//cible.merge(mobile);
    				//cible.persist(mobile);
    			}
    		}
    		return mobile;
    	}
     
    	private Email transfertEmail(ResultSet rs, Contact contact)
    			throws SQLException {
    		Email email = null;
    		String mail = rs.getString("email_1");
    		if (mail != null && !mail.contains("@")) {
    			mail = rs.getString("email");
    		}
    		if (mail != null && mail.contains("@")) {
    			mail.trim();
    			String[] part_mail = mail.split("@");
    			email = new Email(part_mail[0], part_mail[1], contact);
    			if (!cible.contains(email)) {
    				//cible.merge(email);
    				//cible.persist(email);
    			}
    		}
    		return email;
    	}
     
    	private Salarie transfertSalarie(ResultSet rs) throws SQLException {
    		String fonction = rs.getString("fonction");
    		fonction = fonction.trim();
    		fonction = fonction.toLowerCase();
    		fonction = fonction.replaceFirst(String.valueOf(fonction.charAt(0)),
    				String.valueOf(fonction.charAt(0)).toUpperCase());
    		Salarie statut = new Salarie(fonction);
    		if (!cible.contains(statut)) {
    			//cible.merge(statut);
    			//cible.persist(statut);
    		}
    		return statut;
    	}
     
    	private Contact transfertContact(ResultSet rs) throws SQLException {
    		StringBuilder sb = new StringBuilder();
    		String titre = rs.getString("genre");
    		String nom = rs.getString("nom");
    		nom = nom.replace("  ", " ");
    		nom.trim();
    		String[] part_nom = nom.split(" ");
    		for (String s : part_nom) {
    			s = s.toLowerCase();
    			s = s.replaceFirst(String.valueOf(s.charAt(0)),
    					String.valueOf(s.charAt(0)).toUpperCase());
    			sb.append(s);
    			sb.append(" ");
    		}
    		nom = sb.toString();
    		nom = nom.trim();
    		Contact contact = new Contact(titre, nom, "");
    		if (!cible.contains(contact)) {
    			//cible.merge(contact);
    			//cible.persist(contact);
    		}
    		return contact;
    	}
     
    	private Entreprise transfertEntreprise(ResultSet rs, Lieu lieu)
    			throws SQLException {
     
    		Entreprise entreprise = null;
    		// Mise au propre du nom de l'entreprise
    		String nomEntreprise = rs.getString("nom_org");
    		nomEntreprise = nomEntreprise.replace("  ", " ");
    		if (Character.isWhitespace(nomEntreprise.charAt(0))) {
    			nomEntreprise.replaceFirst(" ", "");
    		}
    		nomEntreprise = nomEntreprise.toLowerCase();
    		nomEntreprise.replaceFirst(String.valueOf(nomEntreprise.charAt(0)),
    				String.valueOf(nomEntreprise.charAt(0)).toUpperCase());
    		nomEntreprise = nomEntreprise.trim();
    		entreprise = new Entreprise(lieu, nomEntreprise);
    		if (!cible.contains(entreprise)) {
    			//cible.merge(entreprise);
    			//cible.persist(entreprise);
    		}
    		return entreprise;
    	}
     
    	private Lieu transfertLieu(ResultSet rs) throws SQLException {
    		Lieu lieu = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(rs.getString("adresse1").trim());
    		sb.append(" ");
    		sb.append(rs.getString("adresse2").trim());
    		String adresse = sb.toString();
    		String ville = rs.getString("ville").trim();
    		String cpString = rs.getString("cp");
    		Integer cp = Integer.parseInt(cpString.trim());
    		lieu = new Lieu(adresse, cp, ville);
    		if (!cible.contains(lieu)) {
    			//cible.merge(lieu);
    			//cible.persist(lieu);
    		}
    		return lieu;
    	}
     
    	public void end() {
    		cible.flush(); //ICI L'ERREUR DE CONTRAINTE UNIQUE
    		cible.close();
    		try {
    			con.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
     
    }
    et les entités concernées :

    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    @Entity
    @SequenceGenerator(name = "cso_id_seq", sequenceName = "cso_id_seq", allocationSize = 1)
    @Table(name = "cso", schema = "public", uniqueConstraints = { @UniqueConstraint(columnNames = {
    		"idcontact", "idstatut", "idorga" }) })
    public class ContactStatutOrga implements Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = -5089426913727587852L;
    	private int liaisonid;
    	private Contact contact;
    	private Orga orga;
    	private Statut statut;
    	private Set<Lignefixe> lignes = new HashSet<Lignefixe>();
    	private boolean actuel;
    	private Date debut;
    	private Date fin;
     
    	/**
             * 
             */
    	public ContactStatutOrga() {
    	}
     
    	/**
             * @param contact
             * @param orga
             * @param statut
             * @param actuel
             */
    	public ContactStatutOrga(Contact contact, Orga orga, Statut statut,
    			boolean actuel) {
    		this.addContact(contact);
    		this.addOrga(orga);
    		this.addStatut(statut);
    		this.actuel = actuel;
    	}
     
    	/**
             * @param contact
             * @param orga
             * @param statut
             * @param lignes
             * @param actuel
             * @param debut
             * @param fin
             */
    	public ContactStatutOrga(Contact contact, Orga orga, Statut statut,
    			Set<Lignefixe> lignes, boolean actuel, Date debut, Date fin) {
    		this.addContact(contact);
    		this.addOrga(orga);
    		this.addStatut(statut);
    		this.lignes = lignes;
    		this.actuel = actuel;
    		this.debut = debut;
    		this.fin = fin;
    	}
     
    	/**
             * @return the liaisonid
             */
    	@Id
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cso_id_seq")
    	@Column(name = "idcso", unique = true, nullable = false)
    	public int getLiaisonid() {
    		return liaisonid;
    	}
     
    	/**
             * @param liaisonid
             *            the liaisonid to set
             */
    	public void setLiaisonid(int liaisonid) {
    		this.liaisonid = liaisonid;
    	}
     
    	/**
             * @return the contact
             */
    	@ManyToOne(cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
    	@JoinColumn(name = "idcontact", nullable=false)
    	public Contact getContact() {
    		return contact;
    	}
     
    	/**
             * @param contact
             *            the contact to set
             */
    	public void setContact(Contact contact) {
    		this.contact = contact;
    	}
     
    	public void addContact(Contact contact) {
    		setContact(contact);
    		contact.getLiaison().add(this);
    	}
    	/**
             * @return the orga
             */
    	@ManyToOne(cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
    	@JoinColumn(name = "idorga", nullable=false)
    	public Orga getOrga() {
    		return orga;
    	}
     
    	/**
             * @param orga
             *            the orga to set
             */
    	public void setOrga(Orga orga) {
    		this.orga = orga;
    	}
     
    	public void addOrga(Orga orga) {
    		this.orga = orga;
    		orga.getLiaison().add(this);
    	}
     
    	/**
             * @return the statut
             */
    	@ManyToOne(cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
    	@JoinColumn(name = "idstatut", nullable=false)
    	public Statut getStatut() {
    		return statut;
    	}
     
    	/**
             * @param statut
             *            the statut to set
             */
    	public void setStatut(Statut statut) {
    		this.statut = statut;
    	}
     
     
    	public void addStatut(Statut statut){
    		this.statut = statut;
    		statut.getLiaison().add(this);
    	}
    	@Column(name = "actuel", nullable = false)
    	public boolean isActuel() {
    		return this.actuel;
    	}
     
    	public void setActuel(boolean actuel) {
    		this.actuel = actuel;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "debut", length = 13)
    	public Date getDebut() {
    		return this.debut;
    	}
     
    	public void setDebut(Date debut) {
    		this.debut = debut;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "fin", length = 13)
    	public Date getFin() {
    		return this.fin;
    	}
     
    	public void setFin(Date fin) {
    		this.fin = fin;
    	}
     
    	/**
             * @return the lignes
             */
    	@OneToMany(mappedBy="cso", cascade={ CascadeType.ALL }, orphanRemoval=true)
    	public Set<Lignefixe> getLignes() {
    		return lignes;
    	}
     
    	/**
             * @param lignes the lignes to set
             */
    	public void setLignes(Set<Lignefixe> lignes) {
    		this.lignes = lignes;
    	}
     
    	public void addLignefixe(Lignefixe ligne){
    		this.getLignes().add(ligne);
    		ligne.setCso(this);
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(getContact().getPrenom());
    		builder.append(" ");
    		builder.append(getContact().getNom());
    		builder.append(" ");
    		builder.append(getStatut().toString());
    		builder.append(" à ");
    		builder.append(getOrga().getNom());
    		builder.append(" ");
    		if (actuel && getDebut() != null) {
    			builder.append(" depuis le ");
    			builder.append(getDebut().toString());
    		} else if (getDebut() != null && getFin() != null) {
    			builder.append(" de ");
    			builder.append(getDebut().toString());
    			builder.append(" à ");
    			builder.append(getFin().toString());
    		}
    		return builder.toString();
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((contact == null) ? 0 : contact.hashCode());
    		result = prime * result + ((orga == null) ? 0 : orga.hashCode());
    		result = prime * result + ((statut == null) ? 0 : statut.hashCode());
    		return result;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		ContactStatutOrga other = (ContactStatutOrga) obj;
    		if (contact == null) {
    			if (other.contact != null)
    				return false;
    		} else if (!contact.equals(other.contact))
    			return false;
    		if (orga == null) {
    			if (other.orga != null)
    				return false;
    		} else if (!orga.equals(other.orga))
    			return false;
    		if (statut == null) {
    			if (other.statut != null)
    				return false;
    		} else if (!statut.equals(other.statut))
    			return false;
    		return true;
    	}
     
    }
    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    @Entity
    @Table(name = "contact", schema = "public")
    @SequenceGenerator(name = "contact_id_seq", sequenceName = "contact_id_seq", allocationSize = 1)
    @NamedQueries({
    		@NamedQuery(name = "loadContactByNomPrenom", query = "SELECT c FROM Contact c WHERE c.nom LIKE :nom AND c.prenom LIKE :prenom"),
    		@NamedQuery(name = "loadContactByVille", query = "SELECT c FROM Contact c, Lieu l WHERE l.ville LIKE :ville"),
    		@NamedQuery(name = "loadContactByOrga", query = "SELECT c FROM Contact c, Orga o WHERE o.nom LIKE :nom"), })
    public class Contact implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 3021720099087198748L;
    	private int idcontact;
    	private String titre;
    	private String nom;
    	private String prenom;
    	private Date datenaissance;
    	private String statutmarital;
    	private String comments;
    	private Set<Email> emails = new HashSet<Email>();
    	private Set<Mobile> mobiles = new HashSet<Mobile>();
    	private Set<Lieu> lieux = new HashSet<Lieu>();
    	private Set<Doc> documents = new HashSet<Doc>();
    	private Set<ContactStatutOrga> liaison = new HashSet<ContactStatutOrga>();
     
    	/**
             * 
             */
    	public Contact() {
    	}
     
    	/**
             * @param nom
             * @param prenom
             * @param titre
             */
    	public Contact(String titre, String nom, String prenom) {
    		this.titre = titre;
    		this.nom = nom;
    		this.prenom = prenom;
    	}
     
    	/**
             * @param nom
             * @param prenom
             * @param datenaissance
             * @param statutmarital
             * @param comments
             * @param statuts
             * @param emails
             * @param mobiles
             * @param lieux
             * @param documents
             */
    	public Contact(String titre, String nom, String prenom, Date datenaissance,
    			String statutmarital, String comments, Set<Email> emails,
    			Set<Mobile> mobiles, Set<Lieu> lieus, Set<Doc> documents) {
    		this.titre = titre;
    		this.nom = nom;
    		this.prenom = prenom;
    		this.datenaissance = datenaissance;
    		this.statutmarital = statutmarital;
    		this.comments = comments;
    		for(Email e:emails){
    			this.addEmail(e);
    		}
    		for(Mobile m:mobiles){
    			this.addMobile(m);
    		}
    		for(Lieu l:lieus){
    			this.addLieu(l);
    		}
    		for(Doc d:documents){
    			this.addDocument(d);
    		}
    	}
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "contact_id_seq")
    	@Column(name = "idcontact", unique = true, nullable = false)
    	public int getIdcontact() {
    		return this.idcontact;
    	}
     
    	/**
             * @param idcontact
             *            the idcontact to set
             */
    	public void setIdcontact(int idcontact) {
    		this.idcontact = idcontact;
    	}
     
    	/**
             * @return the titre
             */
    	@Column(name = "titre", nullable = false)
    	public String getTitre() {
    		return titre;
    	}
     
    	/**
             * @param titre
             *            the titre to set
             */
    	public void setTitre(String titre) {
    		this.titre = titre;
    	}
     
    	@Column(name = "nom", nullable = false)
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	@Column(name = "prenom", nullable = false)
    	public String getPrenom() {
    		return this.prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "datenaissance", length = 13)
    	public Date getDatenaissance() {
    		return this.datenaissance;
    	}
     
    	public void setDatenaissance(Date datenaissance) {
    		this.datenaissance = datenaissance;
    	}
     
    	@Column(name = "statutmarital")
    	public String getStatutmarital() {
    		return this.statutmarital;
    	}
     
    	public void setStatutmarital(String statutmarital) {
    		this.statutmarital = statutmarital;
    	}
     
    	@Column(name = "comments")
    	public String getComments() {
    		return this.comments;
    	}
     
    	public void setComments(String comments) {
    		this.comments = comments;
    	}
     
    	@OneToMany(fetch = FetchType.LAZY, mappedBy = "contact",cascade={ CascadeType.ALL }, orphanRemoval = true)
    	public Set<Email> getEmails() {
    		return this.emails;
    	}
     
    	public void setEmails(Set<Email> emails) {
    		this.emails = emails;
    	}
     
    	public void addEmail(Email email){
    		this.getEmails().add(email);
    		email.setContact(this);
    	}
     
    	@OneToMany(fetch = FetchType.LAZY, mappedBy = "contact",cascade={ CascadeType.ALL }, orphanRemoval = true)
    	public Set<Mobile> getMobiles() {
    		return this.mobiles;
    	}
     
    	public void setMobiles(Set<Mobile> mobiles) {
    		this.mobiles = mobiles;
    	}
     
    	public void addMobile(Mobile mobile){
    		this.getMobiles().add(mobile);
    		mobile.setContact(this);
    	}
     
    	@ManyToMany(fetch = FetchType.LAZY,cascade={ CascadeType.PERSIST, CascadeType.MERGE })
    	@JoinTable(name = "adresse_perso", schema = "public", joinColumns = { @JoinColumn(name = "habitant", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "adresse", nullable = false, updatable = false) })
    	public Set<Lieu> getLieux() {
    		return this.lieux;
    	}
     
    	public void setLieux(Set<Lieu> lieux) {
    		this.lieux = lieux;
    	}
     
    	public void addLieu(Lieu lieu){
    		this.getLieux().add(lieu);
    		lieu.getContacts().add(this);
    	}
     
    	/**
             * @return the documents
             */
    	@ManyToMany(fetch = FetchType.LAZY, cascade={ CascadeType.PERSIST, CascadeType.MERGE })
    	@JoinTable(name = "docs_contacts", joinColumns = { @JoinColumn(name = "idcontact", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "path", nullable = false) })
    	public Set<Doc> getDocuments() {
    		return documents;
    	}
     
    	/**
             * @param documents
             *            the documents to set
             */
    	public void setDocuments(Set<Doc> documents) {
    		this.documents = documents;
    	}
     
    	public void addDocument(Doc document){
    		this.getDocuments().add(document);
    		document.getContacts().add(this);
    	}
     
    	/**
             * @return the liaison
             */
    	@OneToMany(fetch = FetchType.LAZY, mappedBy = "contact", cascade={ CascadeType.ALL }, orphanRemoval = true)
    	public Set<ContactStatutOrga> getLiaison() {
    		return liaison;
    	}
     
    	/**
             * @param liaison
             *            the liaison to set
             */
    	public void setLiaison(Set<ContactStatutOrga> liaison) {
    		this.liaison = liaison;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(prenom);
    		builder.append(nom);
    		for (ContactStatutOrga cso : liaison) {
    			if (cso.isActuel()) {
    				builder.append(", ");
    				builder.append(cso.getStatut().toString());
    				builder.append(" à ");
    				builder.append(cso.getOrga().getNom());
    				if (cso.getDebut() != null) {
    					builder.append(" depuis le ");
    					builder.append(cso.getDebut());
    				}
    				break;
    			}
    		}
    		if (comments != null) {
    			builder.append(" (");
    			builder.append(comments);
    			builder.append(")");
    		}
    		return builder.toString();
     
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
    		result = prime * result + ((prenom == null) ? 0 : prenom.hashCode());
    		return result;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Contact other = (Contact) obj;
    		if (nom == null) {
    			if (other.nom != null)
    				return false;
    		} else if (!nom.equals(other.nom))
    			return false;
    		if (prenom == null) {
    			if (other.prenom != null)
    				return false;
    		} else if (!prenom.equals(other.prenom))
    			return false;
    		return true;
    	}
     
    }
    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
    @Entity
    @Table(name = "statut", schema = "public")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @SequenceGenerator(name="statut_id_seq", sequenceName="statut_id_seq", allocationSize=1)
    @DiscriminatorColumn(name = "type_statut")
    public class Statut implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 2432774682596038261L;
    	/**
             * 
             */
    	private int idstatut;
    	private String fonction;
    	private Set<ContactStatutOrga> liaison = new HashSet<ContactStatutOrga>();
     
    	protected Statut() {
    	}
     
    	/**
             * @param fonction
             */
    	public Statut(String fonction) {
    		this.fonction = fonction;
    	}
     
     
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="statut_id_seq")
    	@Column(name = "idstatut", unique = true, nullable = false)
    	public int getIdstatut() {
    		return this.idstatut;
    	}
     
    	/**
             * @param idstatut the idstatut to set
             */
    	public void setIdstatut(int idstatut) {
    		this.idstatut = idstatut;
    	}
     
    	/**
             * @return the fonction
             */
    	@Column(name = "fonction", nullable = false, unique= true)
    	public String getFonction() {
    		return fonction;
    	}
     
    	/**
             * @param fonction
             *            the fonction to set
             */
    	public void setFonction(String fonction) {
    		this.fonction = fonction;
    	}
     
     
     
    	/**
             * @return the liaison
             */
    	@OneToMany(fetch= FetchType.LAZY, mappedBy="statut", cascade={CascadeType.ALL},orphanRemoval=true)
    	public Set<ContactStatutOrga> getLiaison() {
    		return liaison;
    	}
     
    	/**
             * @param liaison the liaison to set
             */
    	public void setLiaison(Set<ContactStatutOrga> liaison) {
    		this.liaison = liaison;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(fonction);
    		return builder.toString();
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result
    				+ ((fonction == null) ? 0 : fonction.hashCode());
    		return result;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Statut other = (Statut) obj;
    		if (fonction == null) {
    			if (other.fonction != null)
    				return false;
    		} else if (!fonction.equals(other.fonction))
    			return false;
    		return true;
    	}
     
    }
    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    @Entity
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name = "type_orga")
    @Table(name = "orga", schema = "public")
    @NamedQueries({ @NamedQuery(name = "loadOrgaByVille", query = "SELECT o FROM Orga o, Lieu l WHERE l.ville LIKE :ville") })
    public class Orga implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = -4931746777679288196L;
    	/**
             * 
             */
    	private int idorga;
    	private Set<Lieu> adresses = new HashSet<Lieu>();
    	private String nom;
    	private String siteWeb;
    	private String commentaire;
    	private String typeOrga;
    	private Set<Doc> documents = new HashSet<Doc>();
    	private Set<ContactStatutOrga> liaison = new HashSet<ContactStatutOrga>();
     
    	protected Orga() {
    	}
     
    	public Orga(Lieu lieu, String nom) {
    		this.addAdresse(lieu);
    		this.nom = nom;
    	}
     
    	/**
             * @param adresses
             * @param nom
             * @param siteWeb
             * @param commentaire
             * @param typeOrga
             * @param documents
             */
    	public Orga(Set<Lieu> adresses, String nom, String siteWeb,
    			String commentaire, String typeOrga, Set<Doc> documents) {
    		for(Lieu l:adresses){
    			this.addAdresse(l);
    		}
    		this.nom = nom;
    		this.siteWeb = siteWeb;
    		this.commentaire = commentaire;
    		this.typeOrga = typeOrga;
    		for(Doc d:documents){
    			this.addDocument(d);
    		}
    	}
     
    	@Id
    	@SequenceGenerator(name = "orga_id_seq", sequenceName = "orga_id_seq", allocationSize = 1)
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "orga_id_seq")
    	@Column(name = "idorga", unique = true, nullable = false)
    	public int getIdorga() {
    		return this.idorga;
    	}
     
    	public void setIdorga(int id) {
    		this.idorga = id;
    	}
     
    	@ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.ALL })
    	@JoinTable(name = "adresse_orga", joinColumns = { @JoinColumn(name = "idorga", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "idlieu", nullable = false) })
    	public Set<Lieu> getAdresses() {
    		return this.adresses;
    	}
     
    	public void addAdresse(Lieu lieu){
    		this.getAdresses().add(lieu);
    		lieu.getOrgas().add(this);
    	}
     
    	public void setAdresses(Set<Lieu> lieu) {
    		this.adresses = lieu;
    	}
     
    	@Column(name = "nom", nullable = false, unique=true)
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	/**
             * @return the siteWeb
             */
    	@Column(name = "siteweb")
    	public String getSiteWeb() {
    		return siteWeb;
    	}
     
    	/**
             * @param siteWeb
             *            the siteWeb to set
             */
    	public void setSiteWeb(String siteWeb) {
    		this.siteWeb = siteWeb;
    	}
     
    	/**
             * @return the commentaire
             */
    	@Column(name = "commentaire")
    	public String getCommentaire() {
    		return commentaire;
    	}
     
    	/**
             * @param commentaire
             *            the commentaire to set
             */
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	/**
             * @return the typeOrga
             */
    	@Column(name = "type_orga", nullable = false, insertable = false, updatable = false)
    	public String getTypeOrga() {
    		return typeOrga;
    	}
     
    	/**
             * @param typeOrga
             *            the typeOrga to set
             */
    	public void setTypeOrga(String typeOrga) {
    		this.typeOrga = typeOrga;
    	}
     
    	/**
             * @return the documents
             */
    	@ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.ALL })
    	@JoinTable(name = "docs_orga", joinColumns = { @JoinColumn(name = "idorga", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "path", nullable = false) })
    	public Set<Doc> getDocuments() {
    		return documents;
    	}
     
    	/**
             * @param documents
             *            the documents to set
             */
    	public void setDocuments(Set<Doc> documents) {
    		this.documents = documents;
    	}
     
    	public void addDocument(Doc document){
    		this.getDocuments().add(document);
    		document.getOrgas().add(this);
    	}
     
    	/**
             * @return the liaison
             */
    	@OneToMany(fetch = FetchType.LAZY, mappedBy = "orga",cascade = { CascadeType.ALL }, orphanRemoval = true)
    	public Set<ContactStatutOrga> getLiaison() {
    		return liaison;
    	}
     
    	/**
             * @param liaison
             *            the liaison to set
             */
    	public void setLiaison(Set<ContactStatutOrga> liaison) {
    		this.liaison = liaison;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(nom);
    		if (commentaire != null) {
    			builder.append(" (");
    			builder.append(commentaire);
    			builder.append(")");
    		}
    		return builder.toString();
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((adresses == null) ? 0 : hashAdresse());
    		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
    		return result;
    	}
     
    	private int hashAdresse() {
    		if (!adresses.isEmpty()) {
    			Lieu[] tabadresses = adresses.toArray(new Lieu[adresses.size()]);
    			return tabadresses[0].hashCode();
    		}
    		return adresses.hashCode();
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Orga other = (Orga) obj;
    		if (adresses == null) {
    			if (other.adresses != null)
    				return false;
    		} else if (!adresses.equals(other.adresses))
    			return false;
    		if (nom == null) {
    			if (other.nom != null)
    				return false;
    		} else if (!nom.equals(other.nom))
    			return false;
    		return true;
    	}
     
    }
    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
    @Entity
    @SequenceGenerator(name = "lieu_id_seq", sequenceName = "lieu_id_seq", allocationSize = 1)
    @Table(name = "lieu", schema = "public", uniqueConstraints = { @UniqueConstraint(columnNames = {
    		"corpAdresse", "cp", "ville" }) })
    public class Lieu implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 4886209405430116057L;
    	/**
             * 
             */
    	private int id;
    	private String adresse;
    	private Integer cp;
    	private String ville;
    	private Set<Contact> contacts = new HashSet<Contact>(0);
    	private Set<Orga> orgas = new HashSet<Orga>(0);
     
    	public Lieu() {
    	}
     
    	/**
             * @param adresse
             * @param cp
             * @param ville
             */
    	public Lieu(String adresse, Integer cp, String ville) {
    		this.adresse = adresse;
    		this.cp = cp;
    		this.ville = ville;
    	}
     
    	/**
             * @param adresse
             * @param cp
             * @param ville
             * @param contact
             * @param orga
             */
    	public Lieu(String adresse, Integer cp, String ville, Contact contact,
    			Orga orga) {
    		this.adresse = adresse;
    		this.cp = cp;
    		this.ville = ville;
    		contact.addLieu(this);
    		orga.addAdresse(this);
    	}
     
    	/**
             * @param adresse
             * @param cp
             * @param ville
             * @param contacts
             * @param orgas
             */
    	public Lieu(String adresse, Integer cp, String ville,
    			Set<Contact> contacts, Set<Orga> orgas) {
    		this.adresse = adresse;
    		this.cp = cp;
    		this.ville = ville;
    		for (Contact c : contacts) {
    			c.addLieu(this);
    		}
    		for (Orga o : orgas) {
    			o.addAdresse(this);
    		}
    	}
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "lieu_id_seq")
    	@Column(name = "id", unique = true, nullable = false)
    	public int getId() {
    		return this.id;
    	}
     
    	public void setId(int id) {
    		this.id = id;
    	}
     
    	@Column(name = "corpAdresse", nullable = false)
    	public String getAdresse() {
    		return this.adresse;
    	}
     
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
     
    	@Column(name = "cp", nullable = false)
    	public Integer getCp() {
    		return this.cp;
    	}
     
    	public void setCp(Integer cp) {
    		this.cp = cp;
    	}
     
    	@Column(name = "ville", nullable = false)
    	public String getVille() {
    		return this.ville;
    	}
     
    	public void setVille(String ville) {
    		this.ville = ville;
    	}
     
    	@ManyToMany(fetch = FetchType.LAZY, mappedBy="lieux", cascade={CascadeType.MERGE,CascadeType.PERSIST})
    	public Set<Contact> getContacts() {
    		return this.contacts;
    	}
     
    	public void setContacts(Set<Contact> contacts) {
    		this.contacts = contacts;
    	}
     
    	@ManyToMany(fetch = FetchType.LAZY, mappedBy="adresses", cascade={CascadeType.PERSIST, CascadeType.MERGE})
    	public Set<Orga> getOrgas() {
    		return this.orgas;
    	}
     
    	public void setOrgas(Set<Orga> orgas) {
    		this.orgas = orgas;
    	}
     
    	/*
    	 * (non-Javadoc);
    	 * 
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(adresse);
    		builder.append(", ");
    		builder.append(System.lineSeparator());
    		builder.append(cp);
    		builder.append(" ");
    		builder.append(ville);
    		return builder.toString();
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((adresse == null) ? 0 : adresse.hashCode());
    		result = prime * result + ((cp == null) ? 0 : cp.hashCode());
    		result = prime * result + ((ville == null) ? 0 : ville.hashCode());
    		return result;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Lieu other = (Lieu) obj;
    		if (adresse == null) {
    			if (other.adresse != null)
    				return false;
    		} else if (!adresse.equals(other.adresse))
    			return false;
    		if (cp == null) {
    			if (other.cp != null)
    				return false;
    		} else if (!cp.equals(other.cp))
    			return false;
    		if (ville == null) {
    			if (other.ville != null)
    				return false;
    		} else if (!ville.equals(other.ville))
    			return false;
    		return true;
    	}
     
    }
    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
    @Entity
    @Table(name = "mobile", schema = "public")
    public class Mobile implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = -1118549081815884436L;
    	/**
             * 
             */
    	private String numero;
    	private Contact contact;
     
    	public Mobile() {
    	}
     
    	public Mobile(String numero, Contact contact) {
    		this.numero = numero;
    		contact.addMobile(this);
    	}
     
    	@Id
    	@Column(name = "numero", unique = true, nullable = false)
    	public String getNumero() {
    		return this.numero;
    	}
     
    	public void setNumero(String numero) {
    		this.numero = numero;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY, cascade= {CascadeType.PERSIST,CascadeType.MERGE})
    	@JoinColumn(name = "utilisateur", nullable = false)
    	public Contact getContact() {
    		return this.contact;
    	}
     
    	public void setContact(Contact contact) {
    		this.contact = contact;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append("mobile :");
    		builder.append(numero);
    		return builder.toString();
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((numero == null) ? 0 : numero.hashCode());
    		return result;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Mobile other = (Mobile) obj;
    		if (numero == null) {
    			if (other.numero != null)
    				return false;
    		} else if (!numero.equals(other.numero))
    			return false;
    		return true;
    	}
     
     
     
    }
    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
    @Entity
    @SequenceGenerator(name = "email_id_seq", sequenceName = "email_id_seq", allocationSize = 1)
    @Table(name = "email", schema = "public", uniqueConstraints = { @UniqueConstraint(columnNames = {
    		"adresse", "domaine"}) })
    public class Email implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 8940266132619507818L;
    	/**
             * 
             */
    	private int id;
    	private String adresse;
    	private String domaine;
    	private Contact contact;
     
    	public Email() {
    	}
     
    	public Email(String adresse, String domaine, Contact contact) {
    		this.adresse = adresse;
    		this.domaine = domaine;
    		contact.addEmail(this);
    	}
     
     
     
    	/**
             * @return the id
             */
    	@Id
    	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "email_id_seq")
    	@Column(name = "idemail", unique = true, nullable = false)
    	public int getId() {
    		return id;
    	}
     
    	/**
             * @param id the id to set
             */
    	public void setId(int id) {
    		this.id = id;
    	}
     
    	/**
             * @return the adresse
             */
    	@Column(name = "adresse", nullable = false)
    	public String getAdresse() {
    		return adresse;
    	}
     
    	/**
             * @param adresse the adresse to set
             */
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
     
    	/**
             * @return the domaine
             */
    	@Column(name = "domaine", nullable = false)
    	public String getDomaine() {
    		return domaine;
    	}
     
    	/**
             * @param domaine the domaine to set
             */
    	public void setDomaine(String domaine) {
    		this.domaine = domaine;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY, cascade={CascadeType.MERGE, CascadeType.PERSIST})
    	@JoinColumn(name = "utilisateur", nullable = false)
    	public Contact getContact() {
    		return this.contact;
    	}
     
    	public void setContact(Contact contact) {
    		this.contact = contact;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(adresse);
    		builder.append("@");
    		builder.append(domaine);
    		return builder.toString();
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((adresse == null) ? 0 : adresse.hashCode());
    		result = prime * result + ((domaine == null) ? 0 : domaine.hashCode());
    		return result;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Email other = (Email) obj;
    		if (adresse == null) {
    			if (other.adresse != null)
    				return false;
    		} else if (!adresse.equals(other.adresse))
    			return false;
    		if (domaine == null) {
    			if (other.domaine != null)
    				return false;
    		} else if (!domaine.equals(other.domaine))
    			return false;
    		return true;
    	}
     
    }
    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
    @Entity
    @Table(name = "lignefixe", schema = "public")
    public class Lignefixe implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = -937081172717161758L;
    	/**
             * 
             */
    	private String numero;
    	private ContactStatutOrga cso;
    	private String typeligne;
     
    	public Lignefixe() {
    	}
     
    	public Lignefixe(String numero, ContactStatutOrga cso, String typeligne) {
    		this.numero = numero;
    		cso.addLignefixe(this);
    		this.typeligne = typeligne;
    	}
     
    	@Id
    	@Column(name = "numero", unique = true, nullable = false)
    	public String getNumero() {
    		return this.numero;
    	}
     
    	public void setNumero(String numero) {
    		this.numero = numero;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE})
    	public ContactStatutOrga getCso() {
    		return this.cso;
    	}
     
    	public void setCso(ContactStatutOrga cso) {
    		this.cso = cso;
    	}
     
    	@Column(name = "typeligne", nullable = false)
    	public String getTypeligne() {
    		return this.typeligne;
    	}
     
    	public void setTypeligne(String typeligne) {
    		this.typeligne = typeligne;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#hashCode()
    	 */
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((numero == null) ? 0 : numero.hashCode());
    		return result;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#equals(java.lang.Object)
    	 */
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		Lignefixe other = (Lignefixe) obj;
    		if (numero == null) {
    			if (other.numero != null)
    				return false;
    		} else if (!numero.equals(other.numero))
    			return false;
    		return true;
    	}
     
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		StringBuilder builder = new StringBuilder();
    		builder.append(typeligne);
    		builder.append(" :");
    		builder.append(numero);
    		return builder.toString();
    	}
     
    }
    et le 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
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    <?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="MaPU">
     
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
     
    		<!-- jta-data-source>java:jboss/datasources/redorg/gestionclients</jta-data-source-->
    		<class>org.redware.redorg.gestionclient.entities.Contact</class>
    		<class>org.redware.redorg.gestionclient.entities.Elu</class>
    		<class>org.redware.redorg.gestionclient.entities.Email</class>
    		<class>org.redware.redorg.gestionclient.entities.Entreprise</class>
    		<class>org.redware.redorg.gestionclient.entities.Lieu</class>
    		<class>org.redware.redorg.gestionclient.entities.Lignefixe</class>
    		<class>org.redware.redorg.gestionclient.entities.Mobile</class>
    		<class>org.redware.redorg.gestionclient.entities.Orga</class>
    		<class>org.redware.redorg.gestionclient.entities.Salarie</class>
    		<class>org.redware.redorg.gestionclient.entities.Statut</class>
    		<class>org.redware.redorg.gestionclient.entities.Region</class>
    		<class>org.redware.redorg.gestionclient.entities.Commune</class>
    		<class>org.redware.redorg.gestionclient.entities.Departement</class>
    		<class>org.redware.redorg.gestionclient.entities.Doc</class>
    		<class>org.redware.redorg.gestionclient.entities.ContactStatutOrga</class>
    		<properties>
    			<property name="hibernate.connection.username" value="" />
    			<property name="hibernate.connection.password" value="" />
    			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
    			<property name="hibernate.connection.url"
    				value="jdbc:postgresql://lereste" />
    			<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
    			<property name="hibernate.hbm2ddl.auto" value="create-drop" />
    		</properties>
     
    	</persistence-unit>
    </persistence>
    Entreprise et Salarie étendent Orga et Statut sans y apporté de grosses modif, je vous les épargne. J'ai pensé à un problème de cascade, mais je ne trouve pas. Je sais que ça fait pas mal de code à lire, mais si quelqu'un peut m'aider...

  2. #2
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    la generation du id ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    @Id
    	@Column(name = "numero", unique = true, nullable = false)
    	public String getNumero() {
    		return this.numero;
    	}
    peut causer un probleme, comment est ce que tu geres cela?


    Eric

  3. #3
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    Justement je ne le gérais pas. Je l'ai remarqué en postant, et j'ai donc rajouté à la classe TransfertDAO deux List, une pour les mobiles et une pour les fixes, et modifié comme suit la fonction transfertMobile :

    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
     
    	private Mobile transfertMobile(ResultSet rs, String type, Contact contact)
    			throws SQLException {
    		String numeroMobile = rs.getString(type);
    		Mobile mobile = null;
    		if (numeroMobile != null && numeroMobile.length() > 8) {
    			numeroMobile.trim();
    			numeroMobile.replaceAll(" ", "");
    			numeroMobile.replaceAll(".", "");
    			for (Mobile m : mobileMappe) {
    				if (m.getNumero().equals(numeroMobile)) {
    					mobile = m;
    				}
    			}
    			if (mobile == null) {
    				mobile = new Mobile(numeroMobile, contact);
    				mobileMappe.add(mobile);
    			}
    			if (!cible.contains(mobile)) {
    				// cible.merge(mobile);
    				// cible.persist(mobile);
    			}
    		}
    		return mobile;
    	}
    Et de même pour les fixes. Ce qui devrait suffire à gérer le risque de doublon. Mais j'ai toujours la même erreur.

    En fait, elle se produit dès le premier numéro de mobile (4eme résultat du ResultSet, les 3 premiers n'ayant pas de mobile), ce qui rend incohérente la possibilité d'un doublon, puisqu'un seul numéro est mappé. Je pense que le problème est qu'il est présent deux fois le persistence context, mais je ne comprend pas pourquoi...

  4. #4
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    et en faisant:
    au lieu de:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    try {
    				if(!cible.contains(cso)){
    					cible.merge(cso);
    					cible.persist(cso); //ICI L'ERREUR DE DOUBLE ID
    				}
    			} catch (EntityExistsException e) {
    				System.out.println("erreur sur "+cso.getContact().getNom());
    				//System.out.println(cible.find(Mobile.class, e.getLocalizedMessage().split("#")[1].replaceAll("]", "")).toString());
    				e.printStackTrace();
    				break;
    			}
    tu faisais:
    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
     
    try {
     
    					cible.save(cso);
      // quand 
      if ( count % 40 == 0 ) {
     
            cible.flush();
            cible.clear();
        }
     
    			} catch (EntityExistsException e) {
    				System.out.println("erreur sur "+cso.getContact().getNom());
    				//System.out.println(cible.find(Mobile.class, e.getLocalizedMessage().split("#")[1].replaceAll("]", "")).toString());
    				e.printStackTrace();
    				break;
    			}
    eric

  5. #5
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    J'avais déjà testé, mais je l'ai refait, par acquis de conscience, mais ça ne change rien. En fait, l'erreur levée sur l'id en doublon l'est dès le premier objet Mobile inséré, autrement dit avant qu'une quelconque autre id n'ai été créée pour une instance de Mobile...

    Par contre cible étant un EntityManager, je l'ai fait avec merge et persist, puisque save est pour les sessions Hibernate

  6. #6
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    je vois que tu inseres plusieurs objets a la fois dans tes listes,
    cela n´est pas bien vu avec Hibernate, t dois a chaque fois que tu inseres un objet dans la liste, sauvegarde d´abord et continuer ton iterartion.

    Eric

  7. #7
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    Si tu fais référence aux objets Lignefixe, ils sont persistés un par un dès qu'ils sont "complets", c'est à dire que le cso leur est passé...

    Bref, j'ai modifié le code : les clefs primaires des numéros de téléphones sont passées sur des séquences plutôt que des id, j'ai enlevé toutes les contraintes d'unicité sauf sur les id, et j'ai modifiés les cascades pour avoir des cascades ALL dans l'ordre suivant :
    cso -> contact -> mobile,email
    cso -> salarie
    cso -> entreprise -> adresse
    cso ->lignefixe

    Je ne lance donc qu'une seule commande merge/persist par tour de boucle while, sur le cso récupéré.

    Je n'ai plus la moindre trace d'erreur... sauf que le flush modifie la valeur de séquences des tables sans pour autant y insérer de données. Qui plus est, là où le pointeur de séquence de la table cso devrait être à 512, soit le nombre de tours de boucle (et le nombre de ligne renvoyé par la requête initiale, j'ai vérifié), il est de 1024 ! Si je me contente de faire merge ou persist (pas les deux), le pointeur est cette fois à 512, mais sans données transférées... Une idé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
    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
     
    public class TransfertDAO {
     
    	private EntityManager cible;
    	private Connection con;
     
    	private Set<Mobile> mobileMappe = new HashSet<Mobile>();
    	private Set<Lignefixe> fixeMappe = new HashSet<Lignefixe>();
    	private Set<Email> mailMappe = new HashSet<Email>();
    	private Set<Lieu> adresseMappe = new HashSet<Lieu>();
    	private Set<Salarie> salarieMappe = new HashSet<Salarie>();
    	private Set<Entreprise> entrepriseMappe = new HashSet<Entreprise>();
     
    	public void init() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		cible = Persistence
    				.createEntityManagerFactory("")
    				.createEntityManager();
    	}
     
    	public void begin() {
    		try {
    			con = DriverManager.getConnection(
    					"jdbc:mysql://");
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		cible.getTransaction().begin();
    	}
     
    	public void transfertCSO() throws SQLException {
     
    		cible.flush();
    		int count = 0;
    		PreparedStatement st = con
    				.prepareStatement("SELECT Fonction.*, Organisation.*, Interlocuteur.* FROM Organisation RIGHT JOIN (Interlocuteur RIGHT JOIN (Fonction RIGHT JOIN Int_Org_Fon ON Fonction.id_fonction = Int_Org_Fon.ID_Fon) ON Interlocuteur.ID_Interlocuteur = Int_Org_Fon.ID_Int) ON Organisation.Id_Organisation = Int_Org_Fon.ID_Org WHERE ((Int_Org_Fon.TYPE) ='ENT') AND Interlocuteur.nom not in (SELECT Interlocuteur.nom From Interlocuteur WHERE Interlocuteur.nom='aucun') ORDER BY Organisation.nom_org, Interlocuteur.nom");
    		ResultSet rs = st.executeQuery();
    		while (rs.next()) {
    			count++;
     
    			Lieu lieu = transfertLieu(rs);
    			Entreprise entreprise = transfertEntreprise(rs, lieu);
    			Contact contact = transfertContact(rs);
    			Salarie salarie = transfertSalarie(rs);
    			transfertEmail(rs, contact);
    			transfertMobile(rs, "mobile", contact);
    			Set<Lignefixe> lignesfixes = transfertFixes(rs, contact);
     
    			ContactStatutOrga cso = new ContactStatutOrga(contact, entreprise,salarie, Boolean.TRUE);
    			try {
    				for (Lignefixe lf : lignesfixes) {
     
    					if (!cible.contains(lf)) {
    						if (!cible.contains(cso)) {
    							//cible.merge(cso);
    							//cible.persist(cso);
    						}
    						lf.setCso(cso);
    					}
    				}
     
    				//cible.merge(cso);
    				cible.persist(cso);
    			} catch (EntityExistsException e) {
    				System.out.println("erreur sur " + cso.getContact().getNom());
    				// System.out.println(cible.find(Mobile.class,
    				// e.getLocalizedMessage().split("#")[1].replaceAll("]",
    				// "")).toString());
    				e.printStackTrace();
    				break;
    			}
    		}
    		System.out.println(count + " cso persistés");
    	}
     
    	private Set<Lignefixe> transfertFixes(ResultSet rs, Contact contact)
    			throws SQLException {
    		String[] prop = new String[] { "Interlocuteur", "Organisation" };
    		String[] type = new String[] { "tel", "fax" };
    		Set<Lignefixe> lignes = new HashSet<Lignefixe>();
    		for (int i = 0; i < prop.length; i++) {
    			for (int j = 0; j < type.length; j++) {
    				Lignefixe lf = transfertLigne(prop[i], type[j], rs, contact);
    				if (lf != null) {
    					lignes.add(lf);
    				}
    			}
    		}
    		return lignes;
    	}
     
    	private Lignefixe transfertLigne(String proprietaire, String type,
    			ResultSet rs, Contact contact) throws SQLException {
    		Lignefixe lf = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(proprietaire);
    		sb.append('.');
    		sb.append(type);
    		String numeroFixe = rs.getString(sb.toString());
    		if (numeroFixe != null && numeroFixe.length() > 8) {
    			numeroFixe.trim();
    			numeroFixe.replaceAll(" ", "");
    			numeroFixe.replaceAll(".", "");
    			if ((numeroFixe.startsWith("06") || numeroFixe.startsWith("07"))) {
    				transfertMobile(rs, sb.toString(), contact);
    			} else
    				for (Lignefixe l : fixeMappe) {
    					if (l.getNumero().equals(numeroFixe)) {
    						lf = l;
    					}
    				}
    			if (lf == null) {
    				lf = new Lignefixe();
    				lf.setNumero(numeroFixe);
    				lf.setTypeligne(type);
    				fixeMappe.add(lf);
    			}
    		}
    		return lf;
    	}
     
    	private Mobile transfertMobile(ResultSet rs, String type, Contact contact)
    			throws SQLException {
    		String numeroMobile = rs.getString(type);
    		Mobile mobile = null;
    		if (numeroMobile != null && numeroMobile.length() > 8) {
    			numeroMobile.trim();
    			numeroMobile.replaceAll(" ", "");
    			numeroMobile.replaceAll(".", "");
    			for (Mobile m : mobileMappe) {
    				if (m.getNumero().equals(numeroMobile)) {
    					mobile = m;
    					// System.out.println(mobile.toString()
    					// + " déjà existant, copie");
    				}
    			}
    			if (mobile == null) {
    				mobile = new Mobile(numeroMobile, contact);
    				mobileMappe.add(mobile);
    				// System.out.println(mobile.toString() + " transféré");
    			}
    			if (!cible.contains(mobile)) {
    				//cible.merge(mobile);
    				//cible.persist(mobile);
    			}
    		}
    		return mobile;
    	}
     
    	private Email transfertEmail(ResultSet rs, Contact contact)
    			throws SQLException {
    		Email email = null;
    		String mail = rs.getString("email_1");
    		if (mail != null && !mail.contains("@")) {
    			mail = rs.getString("email");
    		}
    		if (mail != null && mail.contains("@")) {
    			mail.trim();
    			String[] part_mail = mail.split("@");
    			for (Email e : mailMappe) {
    				if (e.getAdresse().equals(part_mail[0])
    						&& e.getDomaine().equals(part_mail[1])) {
    					email = e;
    				}
    			}
    			if (email == null) {
    				email = new Email(part_mail[0], part_mail[1], contact);
    				mailMappe.add(email);
    			}
    			if (!cible.contains(email)) {
    				//cible.merge(email);
    				//cible.persist(email);
    			}
    		}
    		return email;
    	}
     
    	private Salarie transfertSalarie(ResultSet rs) throws SQLException {
    		Salarie statut = null;
    		String fonction = rs.getString("fonction");
    		fonction = fonction.trim();
    		fonction = fonction.toLowerCase();
    		fonction = fonction.replaceFirst(String.valueOf(fonction.charAt(0)),
    				String.valueOf(fonction.charAt(0)).toUpperCase());
    		for (Salarie s : salarieMappe) {
    			if (s.getFonction().equals(fonction)) {
    				statut = s;
    			}
    		}
    		if (statut == null) {
    			statut = new Salarie(fonction);
    			salarieMappe.add(statut);
    		}
    		if (!cible.contains(statut)) {
    			//cible.merge(statut);
    			//cible.persist(statut);
    		}
    		return statut;
    	}
     
    	private Contact transfertContact(ResultSet rs) throws SQLException {
    		StringBuilder sb = new StringBuilder();
    		String titre = rs.getString("genre");
    		String nom = rs.getString("nom");
    		nom = nom.replace("  ", " ");
    		nom.trim();
    		String[] part_nom = nom.split(" ");
    		for (String s : part_nom) {
    			s = s.toLowerCase();
    			s = s.replaceFirst(String.valueOf(s.charAt(0)),
    					String.valueOf(s.charAt(0)).toUpperCase());
    			sb.append(s);
    			sb.append(" ");
    		}
    		nom = sb.toString();
    		nom = nom.trim();
    		Contact contact = new Contact(titre, nom, "");
    		if (!cible.contains(contact)) {
    			//cible.merge(contact);
    			//cible.persist(contact);
    		}
    		return contact;
    	}
     
    	private Entreprise transfertEntreprise(ResultSet rs, Lieu lieu)
    			throws SQLException {
     
    		Entreprise entreprise = null;
    		// Mise au propre du nom de l'entreprise
    		String nomEntreprise = rs.getString("nom_org");
    		nomEntreprise = nomEntreprise.replace("  ", " ");
    		if (Character.isWhitespace(nomEntreprise.charAt(0))) {
    			nomEntreprise.replaceFirst(" ", "");
    		}
    		nomEntreprise = nomEntreprise.toLowerCase();
    		nomEntreprise.replaceFirst(String.valueOf(nomEntreprise.charAt(0)),
    				String.valueOf(nomEntreprise.charAt(0)).toUpperCase());
    		nomEntreprise = nomEntreprise.trim();
    		for (Entreprise e : entrepriseMappe) {
    			if (e.getNom().equals(nomEntreprise)) {
    				entreprise = e;
    				if (!entreprise.getAdresses().contains(lieu)) {
    					entreprise.addAdresse(lieu);
    				}
    			}
    		}
    		if (entreprise == null) {
    			entreprise = new Entreprise(lieu, nomEntreprise);
    			entrepriseMappe.add(entreprise);
    		}
    		if (!cible.contains(entreprise)) {
    			//cible.merge(entreprise);
    			//cible.persist(entreprise);
    		}
    		return entreprise;
    	}
     
    	private Lieu transfertLieu(ResultSet rs) throws SQLException {
    		Lieu lieu = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(rs.getString("adresse1").trim());
    		sb.append(" ");
    		sb.append(rs.getString("adresse2").trim());
    		String adresse = sb.toString();
    		String ville = rs.getString("ville").trim();
    		String cpString = rs.getString("cp");
    		Integer cp = Integer.parseInt(cpString.trim());
    		for (Lieu l : adresseMappe) {
    			if (l.getAdresse().equals(adresse) && l.getVille().equals(ville)
    					&& l.getCp().equals(cp)) {
    				lieu = l;
    				//System.out.println("copie de " + lieu.toString());
    				//System.out.println();
    			}
    		}
    		if (lieu == null) {
    			lieu = new Lieu(adresse, cp, ville);
    			adresseMappe.add(lieu);
    			//System.out.println("creation de "+lieu.toString());
    			//System.out.println();
    		}
    		if (!cible.contains(lieu)) {
    			//cible.merge(lieu);
    			//cible.persist(lieu);
    		}
    		return lieu;
    	}
     
    	public void end() {
    		for(Entry e:cible.getProperties().entrySet()){
    		System.out.print(e.getKey());
    		System.out.print(" = ");
    		System.out.println(e.getValue());
    		}
    		cible.flush();
    		cible.close();
    		try {
    			con.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
     
    }

  8. #8
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    J'ai trouvé! En fait, je me mélangeais les pinceaux avec merge et persist, et je faisait un merge (et même plusieurs!) avant de persister mon entité maitresse (cso). Une fois le problème réglé, j'ai pu remettre tous les cascade prévus, et ça marche. Le seul problème qui me reste, c'est avec les ligne fixe partagées entre plusieurs contacts, ce qui n'est pas vraiment prévu par le modèle de données. Mais je vous donne le code qui solutionne le problème de base :

    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
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
     
    public class TransfertDAO {
     
    	private EntityManager cible;
    	private Connection con;
     
    	int count = 0;
     
    	private Set<Mobile> mobileMappe = new HashSet<Mobile>();
    	private Set<Lignefixe> fixeMappe = new HashSet<Lignefixe>();
    	private Set<Email> mailMappe = new HashSet<Email>();
    	private Set<Lieu> adresseMappe = new HashSet<Lieu>();
    	private Set<Salarie> salarieMappe = new HashSet<Salarie>();
    	private Set<Entreprise> entrepriseMappe = new HashSet<Entreprise>();
     
    	public void init() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		cible = Persistence
    				.createEntityManagerFactory("")
    				.createEntityManager();
    	}
     
    	public void begin() {
    		try {
    			con = DriverManager.getConnection(
    					"jdbc:mysql://");
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		cible.getTransaction().begin();
    	}
     
    	public void transfertCSO() throws SQLException {
     
    		cible.flush();
    		PreparedStatement st = con
    				.prepareStatement("SELECT Fonction.*, Organisation.*, Interlocuteur.* FROM Organisation RIGHT JOIN (Interlocuteur RIGHT JOIN (Fonction RIGHT JOIN Int_Org_Fon ON Fonction.id_fonction = Int_Org_Fon.ID_Fon) ON Interlocuteur.ID_Interlocuteur = Int_Org_Fon.ID_Int) ON Organisation.Id_Organisation = Int_Org_Fon.ID_Org WHERE ((Int_Org_Fon.TYPE) ='ENT') AND Interlocuteur.nom not in (SELECT Interlocuteur.nom From Interlocuteur WHERE Interlocuteur.nom='aucun') ORDER BY Organisation.nom_org, Interlocuteur.nom");
    		ResultSet rs = st.executeQuery();
    		while (rs.next()) {
    			count++;
     
    			Lieu lieu = transfertLieu(rs);
    			Entreprise entreprise = transfertEntreprise(rs, lieu);
    			Contact contact = transfertContact(rs);
    			Salarie salarie = transfertSalarie(rs);
    			transfertEmail(rs, contact);
    			transfertMobile(rs, "mobile", contact);
    			Set<Lignefixe> lignesfixes = transfertFixes(rs, contact);
     
    			ContactStatutOrga cso = new ContactStatutOrga(contact, entreprise,salarie, Boolean.TRUE);
    			try {
    				if (!cible.contains(cso)) {
    					cible.persist(cso);
    				}
    				for (Lignefixe lf : lignesfixes) {
    					if(cible.contains(lf)){
    						System.out.println("déjà mappé!"+count);
    					}
    					if (!cso.getLignes().contains(lf)) {
    						cso.addLignefixe(lf);
    						cible.merge(cso);
    						cible.persist(cso);
    					}
    				}
    				cible.merge(cso);
    				//System.out.println(count+": cso id="+cso.getLiaisonid());
    				//System.out.println("-------------------------------");
    			} catch (Exception e) {
    				System.out.println("erreur sur " + cso.getContact().getNom());
    				e.printStackTrace();
    				break;
    			}
    		}
    		System.out.println(count + " resulats mappés depuis dans la base d'origine");
    	}
     
    	private Set<Lignefixe> transfertFixes(ResultSet rs, Contact contact)
    			throws SQLException {
    		String[] prop = new String[] { "Interlocuteur", "Organisation" };
    		String[] type = new String[] { "tel", "fax" };
    		Set<Lignefixe> lignes = new HashSet<Lignefixe>();
    		for (int i = 0; i < prop.length; i++) {
    			for (int j = 0; j < type.length; j++) {
    				Lignefixe lf = transfertLigne(prop[i], type[j], rs, contact);
    				if (lf != null) {
    					lignes.add(lf);
    				}
    			}
    		}
    		return lignes;
    	}
     
    	private Lignefixe transfertLigne(String proprietaire, String type,
    			ResultSet rs, Contact contact) throws SQLException {
    		Lignefixe lf = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(proprietaire);
    		sb.append('.');
    		sb.append(type);
    		String numeroFixe = rs.getString(sb.toString());
    		if (numeroFixe != null && numeroFixe.length() > 8) {
    			numeroFixe.trim();
    			numeroFixe.replaceAll(" ", "");
    			numeroFixe.replaceAll(".", "");
    			if ((numeroFixe.startsWith("06") || numeroFixe.startsWith("07"))) {
    				transfertMobile(rs, sb.toString(), contact);
    			} else
    				for (Lignefixe l : fixeMappe) {
    					if (l.getNumero().equals(numeroFixe)) {
    						lf = l;
    					}
    				}
    			if (lf == null) {
    				lf = new Lignefixe();
    				lf.setNumero(numeroFixe);
    				lf.setTypeligne(type);
    				if(numeroFixe.equals("01 40 06 67 55")||lf.getNumero().equals("01 40 06 67 55"))System.out.println("fixe mappe pour id "+count);
    				fixeMappe.add(lf);
    			}
    		}
    		return lf;
    	}
     
    	private Mobile transfertMobile(ResultSet rs, String type, Contact contact)
    			throws SQLException {
    		String numeroMobile = rs.getString(type);
    		Mobile mobile = null;
    		if (numeroMobile != null && numeroMobile.length() > 8) {
    			numeroMobile.trim();
    			numeroMobile.replaceAll(" ", "");
    			numeroMobile.replaceAll(".", "");
    			for (Mobile m : mobileMappe) {
    				if (m.getNumero().equals(numeroMobile)) {
    					mobile = m;
    				}
    			}
    			if (mobile == null) {
    				mobile = new Mobile(numeroMobile, contact);
    				mobileMappe.add(mobile);
    			}
    			if (!cible.contains(mobile)) {
    				//cible.persist(mobile);
    			}
    		}
    		return mobile;
    	}
     
    	private Email transfertEmail(ResultSet rs, Contact contact)
    			throws SQLException {
    		Email email = null;
    		String mail = rs.getString("email_1");
    		if (mail != null && !mail.contains("@")) {
    			mail = rs.getString("email");
    		}
    		if (mail != null && mail.contains("@")) {
    			mail.trim();
    			String[] part_mail = mail.split("@");
    			for (Email e : mailMappe) {
    				if (e.getAdresse().equals(part_mail[0])
    						&& e.getDomaine().equals(part_mail[1])) {
    					email = e;
    				}
    			}
    			if (email == null) {
    				email = new Email(part_mail[0], part_mail[1], contact);
    				mailMappe.add(email);
    			}
    			if (!cible.contains(email)) {
    				//cible.persist(email);
    			}
    		}
    		return email;
    	}
     
    	private Salarie transfertSalarie(ResultSet rs) throws SQLException {
    		Salarie statut = null;
    		String fonction = rs.getString("fonction");
    		fonction = fonction.trim();
    		fonction = fonction.toLowerCase();
    		fonction = fonction.replaceFirst(String.valueOf(fonction.charAt(0)),
    				String.valueOf(fonction.charAt(0)).toUpperCase());
    		for (Salarie s : salarieMappe) {
    			if (s.getFonction().equals(fonction)) {
    				statut = s;
    			}
    		}
    		if (statut == null) {
    			statut = new Salarie(fonction);
    			salarieMappe.add(statut);
    		}
    		if (!cible.contains(statut)) {
    			//cible.persist(statut);
    		}
    		return statut;
    	}
     
    	private Contact transfertContact(ResultSet rs) throws SQLException {
    		StringBuilder sb = new StringBuilder();
    		String titre = rs.getString("genre");
    		String nom = rs.getString("nom");
    		nom = nom.replace("  ", " ");
    		nom.trim();
    		String[] part_nom = nom.split(" ");
    		for (String s : part_nom) {
    			s = s.toLowerCase();
    			s = s.replaceFirst(String.valueOf(s.charAt(0)),
    					String.valueOf(s.charAt(0)).toUpperCase());
    			sb.append(s);
    			sb.append(" ");
    		}
    		nom = sb.toString();
    		nom = nom.trim();
    		Contact contact = new Contact(titre, nom, "");
    		if (!cible.contains(contact)) {
    			//cible.persist(contact);
    		}
    		return contact;
    	}
     
    	private Entreprise transfertEntreprise(ResultSet rs, Lieu lieu)
    			throws SQLException {
     
    		Entreprise entreprise = null;
    		// Mise au propre du nom de l'entreprise
    		String nomEntreprise = rs.getString("nom_org");
    		nomEntreprise = nomEntreprise.replace("  ", " ");
    		if (Character.isWhitespace(nomEntreprise.charAt(0))) {
    			nomEntreprise.replaceFirst(" ", "");
    		}
    		nomEntreprise = nomEntreprise.toLowerCase();
    		nomEntreprise.replaceFirst(String.valueOf(nomEntreprise.charAt(0)),
    				String.valueOf(nomEntreprise.charAt(0)).toUpperCase());
    		nomEntreprise = nomEntreprise.trim();
    		for (Entreprise e : entrepriseMappe) {
    			if (e.getNom().equals(nomEntreprise)) {
    				entreprise = e;
    				if (!entreprise.getAdresses().contains(lieu)) {
    					entreprise.addAdresse(lieu);
    				}
    			}
    		}
    		if (entreprise == null) {
    			entreprise = new Entreprise(lieu, nomEntreprise);
    			entrepriseMappe.add(entreprise);
    		}
    		if (!cible.contains(entreprise)) {
    			//cible.persist(entreprise);
    		}
    		return entreprise;
    	}
     
    	private Lieu transfertLieu(ResultSet rs) throws SQLException {
    		Lieu lieu = null;
    		StringBuilder sb = new StringBuilder();
    		sb.append(rs.getString("adresse1").trim());
    		sb.append(" ");
    		sb.append(rs.getString("adresse2").trim());
    		String adresse = sb.toString();
    		String ville = rs.getString("ville").trim();
    		String cpString = rs.getString("cp");
    		Integer cp = Integer.parseInt(cpString.trim());
    		for (Lieu l : adresseMappe) {
    			if (l.getAdresse().equals(adresse) && l.getVille().equals(ville)
    					&& l.getCp().equals(cp)) {
    				lieu = l;
    			}
    		}
    		if (lieu == null) {
    			lieu = new Lieu(adresse, cp, ville);
    			adresseMappe.add(lieu);
    		}
    		if (!cible.contains(lieu)) {
    			//cible.persist(lieu);
    		}
    		return lieu;
    	}
     
    	public void end() {
    		cible.flush();
    		cible.getTransaction().commit();
    		try {
    			test();
    		} catch (SQLException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
    		cible.close();
    		try {
    			con.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    }
    Quant au fait que les séquences étaient incrémentées sans que les données soient écrites pour autant, c'est juste que j'avais oublié que je ne travaillé pas en JTA, et que donc il fallait faire un commit...

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/08/2006, 00h35
  2. [WD10] Problème de doublons
    Par routmout dans le forum WinDev
    Réponses: 5
    Dernier message: 07/06/2006, 19h36
  3. Problème de doublons
    Par RapidJul dans le forum Requêtes
    Réponses: 1
    Dernier message: 05/05/2006, 17h08
  4. Réponses: 7
    Dernier message: 30/01/2006, 22h36
  5. [access] Problème de doublons
    Par Invité dans le forum Langage SQL
    Réponses: 2
    Dernier message: 04/05/2005, 10h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo