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

Hibernate Java Discussion :

Erreur "java.lang.IllegalStateException: During synchronization a new object was found throug"


Sujet :

Hibernate Java

  1. #1
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut Erreur "java.lang.IllegalStateException: During synchronization a new object was found throug"
    Bonjour.
    J'ai un souci avec mon code. Quand je veux inserer des enregistrés je réçois des erreurs.
    le code de l'éxécution
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Famille f1 = new Famille();
     f1.setIlot("xxx");
    f1.setLibelle("xxxx");
    f1.setLot("xxx");
    f1.setPorte("xxx");
    //f1.setStructure(cin);
    service.saveFamilles(new Famille[] { f1});
    Personne p1 = new Personne("xxxxx","xxxx","01/01/1900","xxxxxxx ","xxx","M",true,3,"C://Famille//Monsieur.jpg","07077095","02606434",null);
    p1.setFamille(f1);
    les entité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
    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
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
     
    public class Famille implements Serializable{
        // Champ 
    	@Id
    	@Column(nullable = false)
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	private Long code;
     
    	@Column(nullable = false)
    	@Version
    	private int version;
     
    	@Column(length = 150, nullable = false)
    	private String libelle;
     
    	@Column(length = 10, nullable = false)
    	private String porte;
     
    	@Column(length = 10, nullable = false)
    	private String ilot;
     
    	//@ManyToOne()
    	//@JoinColumn(name = "STRUCTURE", insertable = false, updatable = false)
    	//private Structure structure ;
     
    	@Column(length = 10, nullable = false)
    	private String lot;
     
    	 //	Méthodes
         public Famille(){
     
    	}
     
        // toString
    	public String toString() {
    		return String.format("P[%d,%d,%s,%s,%s,%s]",getVersion(), getCode(), getLibelle(),getPorte(),getLot(),getIlot());//,getStructure().getCode());
    	}
     
    	public Long getCode() {
    		return code;
    	}
     
    	public void setCode(Long code) {
    		this.code = code;
    	}
     
    	public int getVersion() {
    		return version;
    	}
     
    	public void setVersion(int version) {
    		this.version = version;
    	}
     
    	public String getLibelle() {
    		return libelle;
    	}
     
    	public void setLibelle(String libelle) {
    		this.libelle = libelle;
    	}
     
    	public String getPorte() {
    		return porte;
    	}
     
    	public void setPorte(String porte) {
    		this.porte = porte;
    	}
     
    	public String getLot() {
    		return lot;
    	}
     
    	public void setLot(String lot) {
    		this.lot = lot;
    	}
     
    	public String getIlot() {
    		return ilot;
    	}
     
    	public void setIlot(String ilot) {
    		this.ilot = ilot;
    	}
     
    	//public Structure getStructure() {
    	//	return structure;
    	//}
     
    	//public void setStructure(Structure structure) {
    	//	this.structure = structure;
    	//}
    }
     
    public class Personne implements Serializable {
     
    	@Id
    	@Column(nullable = false)
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	private Long matricule;
     
    	@Column(nullable = false)
    	@Version
    	private int version;
     
    	@Column(length = 30, nullable = false)
    	private String nom;
     
    	@Column(length = 150, nullable = false)
    	private String prenom;
     
    	@Column(nullable = false)
    	@Temporal(TemporalType.DATE)
    	private Date datenais;
     
    	@Column(length = 100)
    	private String profession;
     
    	@Column(length = 30)
    	private String rang;
     
    	@Column(length = 10)
    	private String cell1;
    	@Column(length = 10)
    	private String cell2;
    	@Column(length = 10)
    	private String cell3;
     
    	@Column(length = 20)
    	private String type;
     
    	@Column(length = 1)
    	private String sexe;
     
    	@Column(nullable = false)
    	private boolean marie;
     
    	@Column(nullable = true)
    	private int nbenfants;
     
     
    	@Column(length = 20)
    	private String photo;
    	//private Blob photo;
     
    	// relation principale Personne (one) -> Adresse (one)
    	// impl�ment�e par la cl� �trang�re Personne(adresse_id) -> Adresse
    	// cascade insertion Personne -> insertion Adresse
    	// cascade maj Personne -> maj Adresse
    	// cascade suppression Personne -> suppression Adresse
    	// une Personne doit avoir 1 Adresse (nullable=false)
    	// 1 Adresse n'appartient qu'� 1 personne (unique=true)
    	@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
    	@JoinColumn(name = "adresse", unique = true, insertable = false) //, nullable = false)
    	private Adresse adresse;
     
    	// relation Personne (many) -> Activite (many) via une table de jointure PersonneActivite
    	// PersonneActivite5(PERSONNE_ID) est cl� �tang�re sur Personne(id)
    	// PersonneActivite5(ACTIVITE_ID) est cl� �tang�re sur Activite(id)
    	// plus de cascade sur les activit�s
    	// @ManyToMany(cascade={CascadeType.PERSIST})
    	@ManyToMany()
    	@JoinTable(name = "PersonneActivite", joinColumns = @JoinColumn(name = "personne"), inverseJoinColumns = @JoinColumn(name = "activite"))
    	private Set<Activite> activites = new HashSet<Activite>();
     
    	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name = "famille", insertable = false, updatable = true)
    	private Famille famille ;
     
        //@OneToOne(mappedBy = "personne", fetch=FetchType.LAZY)
        //private Occupation occupation;
     
    	// constructeurs
    	public Personne() {
    	}
     
    	public Personne(String nom, String prenom, Date datenaissance, boolean marie, int nbenfants) {
    		setNom(nom);
    		setPrenom(prenom);
    		setDatenaissance(datenaissance);
    		setMarie(marie);
    		setNbenfants(nbenfants);
    	}
     
        public Personne(String nom, String prenom, Date datenaissance,String profession,String rang,String sexe,
                        boolean marie, int nbenfants,String photo,String cell1,String cell2,String cell3) {
    		setNom(nom);
    		setPrenom(prenom);
    		setDatenaissance(datenaissance);
            setProfession(profession);
            setRang(rang);
            setSexe(sexe);
    		setMarie(marie);
    		setNbenfants(nbenfants);
            setPhoto(photo);
            setCell1(cell1);
            setCell2(cell2);
            setCell3(cell3);
    	}
        public Personne(String nom, String prenom, String datenaissance,String profession,String rang,String sexe,
                        boolean marie, int nbenfants,String photo,String cell1,String cell2,String cell3){
    		setNom(nom);
    		setPrenom(prenom);
    		try{
                setDatenaissance(new SimpleDateFormat("dd/MM/yyyy").parse(datenaissance));
            } catch(java.text.ParseException e){
                System.out.println("Error :"+ e.getMessage());
            }
            setProfession(profession);
            setRang(rang);
            setSexe(sexe);
    		setMarie(marie);
    		setNbenfants(nbenfants);
            setPhoto(photo);
            setCell1(cell1);
            setCell2(cell2);
            setCell3(cell3);
    	}
     
    	// toString
    	public String toString() {
    		return String.format("P[%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d,%d,%d]", getVersion(),getMatricule(), getNom(), getPrenom(),
    				new SimpleDateFormat("dd/MM/yyyy").format(getDatenaissance()),getSexe(),getProfession(),getRang(),getCell(),isMarie(),getType(),getNbenfants(),getAdresse().getId(),
    				getFamille().getCode());
    	}
     
    	// getters and setters
    	public Long getMatricule() {
    		return matricule;
    	}
     
    	public void setMatricule(Long matricule) {
    		this.matricule = matricule;
    	}
     
    	public int getVersion() {
    		return version;
    	}
     
    	public void setVersion(int version) {
    		this.version = version;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getPrenom() {
    		return prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public Date getDatenaissance() {
    		return datenais;
    	}
     
    	public void setDatenaissance(Date datenais) {
    		this.datenais = datenais;
    	}
     
    	public String getProfession() {
    		return profession;
    	}
     
    	public void setProfession(String profession) {
    		this.profession = profession;
    	}
     
    	public String getRang() {
    		return rang;
    	}
     
    	public void setRang(String rang) {
    		this.rang = rang;
    	}
     
    	public String getSexe() {
    		return sexe;
    	}
     
    	public void setSexe(String sexe) {
    		this.sexe = sexe;
    	}
     
    	public String getCell() {
    		return String.format("P[%s,%s,%s]", cell1, cell2, cell3);
    	}
     
        public String getCell1() {
    		return cell1;
    	}
        public String getCell2() {
    		return cell2;
    	}
        public String getCell3() {
    		return cell3;
    	}
    	public void setCell1(String cell) {
    		this.cell1 = cell;
    	}
     
    	public void setCell2(String cell) {
    		this.cell2 = cell;
    	}
     
    	public void setCell3(String cell) {
    		this.cell3 = cell;
    	}
     
    	public void setCell(String cell) {
    		if (cell1 == null) {
    		   this.cell1 = cell;
    		}
    		else if (cell2 == null){
    			this.cell2 = cell;
    		}
    		else {
    			this.cell3 = cell;
    		}
    	}
     
    	public boolean isMarie() {
    		return marie;
    	}
     
    	public String getType() {
    		return type;
    	}
     
    	public void setType(String type) {
    		this.type = type;
    	}
     
        public String getPhoto() {
    		return photo;
    	}
     
    	public void setPhoto(String photo) {
    		this.photo = photo;
    	}
     
    	public void setMarie(boolean marie) {
    		this.marie = marie;
    	}
     
    	public int getNbenfants() {
    		return nbenfants;
    	}
     
    	public void setNbenfants(int nbenfants) {
    		this.nbenfants = nbenfants;
    	}
     
    	public Adresse getAdresse() {
    		return adresse;
    	}
     
    	public void setAdresse(Adresse adresse) {
    		this.adresse = adresse;
    	}
     
    	public Set<Activite> getActivites() {
    		return activites;
    	}
     
    	public void setActivites(Set<Activite> activites) {
    		this.activites = activites;
    	}
     
    	public Famille getFamille() {
    		return famille;
    	}
     
    	public void setFamille(Famille famille) {
    		this.famille = famille;
    	}
     
        //public Occupation getOccupation() {
    	//	return occupation;
    	//}
     
    	//public void setOccupation(Occupation occupation) {
    	//	this.occupation = occupation;
    	//}
    }
    l'erreur
    log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
    log4j:WARN Please initialize the log4j system properly.
    [TopLink Info]: 2009.02.17 12:35:08.718--ServerSession(29751107)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
    [TopLink Info]: 2009.02.17 12:35:09.671--ServerSession(29751107)--file:/C:/Netbeans/workspace/NetBeansProjects/SpringHibernateJdbcCinq/build/classes/-jpa login successful
    [TopLink Warning]: 2009.02.17 12:35:10.125--UnitOfWork(18769836)--java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: P[0,null,Famille Coulibaly,1520,1520,1520].
    Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: P[0,null,Famille Coulibaly,1520,1520,1520].; nested exception is java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: P[0,null,Famille Coulibaly,1520,1520,1520].
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:268)
    at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:120)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:460)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy21.savePersonne(Unknown Source)
    at mis.cinq.service.Service.savePersonnes(Service.java:185)
    at mis.cinq.view.InitDB.fill(InitDB.java:79)
    at mis.cinq.view.InitDB.main(InitDB.java:33)
    Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: P[0,null,Famille Coulibaly,1520,1520,1520].
    at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork$1.iterate(RepeatableWriteUnitOfWork.java:124)
    at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.internalIterateReferenceObject(DescriptorIterator.java:174)
    at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.iterateReferenceObjectForMapping(DescriptorIterator.java:281)
    at oracle.toplink.essentials.mappings.ObjectReferenceMapping.iterateOnRealAttributeValue(ObjectReferenceMapping.java:254)
    at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.iterateValueHolderForMapping(DescriptorIterator.java:313)
    at oracle.toplink.essentials.internal.indirection.BasicIndirectionPolicy.iterateOnAttributeValue(BasicIndirectionPolicy.java:186)
    at oracle.toplink.essentials.mappings.ForeignReferenceMapping.iterate(ForeignReferenceMapping.java:571)
    at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.iterate(ObjectBuilder.java:2061)
    at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.iterateReferenceObjects(DescriptorIterator.java:296)
    at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.startIterationOn(DescriptorIterator.java:469)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:145)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.discoverAllUnregisteredNewObjects(UnitOfWorkImpl.java:1278)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.assignSequenceNumbers(UnitOfWorkImpl.java:368)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.collectAndPrepareObjectsForCommit(UnitOfWorkImpl.java:707)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1098)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:91)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:842)
    at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:87)
    at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:45)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:456)
    ... 10 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 8 seconds)

  2. #2
    Membre averti
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    593
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2011
    Messages : 593
    Points : 353
    Points
    353
    Par défaut
    Tu peux nous dire comment t'as résolu ton problème?

  3. #3
    Membre actif Avatar de Roy Miro
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    273
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 273
    Points : 290
    Points
    290
    Par défaut
    Sa classe Famille n'a pas de liste Personne. Il l'a probablement ajoutée.

  4. #4
    Membre averti
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    593
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Juin 2011
    Messages : 593
    Points : 353
    Points
    353
    Par défaut
    Oki merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 15/08/2012, 03h18
  2. Erreur JSF java.lang.IllegalStateException
    Par lamia89 dans le forum JSF
    Réponses: 3
    Dernier message: 08/05/2012, 14h42
  3. Réponses: 2
    Dernier message: 29/07/2011, 11h49
  4. Réponses: 0
    Dernier message: 21/04/2011, 12h04

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