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 :

Exception dans l'ajout 'org.hibernate.StaleStateException'


Sujet :

Hibernate Java

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Autre

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2016
    Messages : 17
    Points : 8
    Points
    8
    Par défaut Exception dans l'ajout 'org.hibernate.StaleStateException'
    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
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    	at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:81)
    	at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
    	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:57)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3013)
    	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2915)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3244)
    	at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:113)
    	at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
    	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
    	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
    	at com.stage.DAO.TacheemployeDAOImpl.addTacheemploye(TacheemployeDAOImpl.java:32)
    	at com.stage.service.TacheemployeServiceImpl.addTacheemploye(TacheemployeServiceImpl.java:30)
    	at com.stage.bean.TacheemployeBean.addTacheemploye(TacheemployeBean.java:217)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
    	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    	at org.springframework.faces.webflow.FlowActionListener.processAction(FlowActionListener.java:71)
    	at org.springframework.faces.model.SelectionTrackingActionListener.processAction(SelectionTrackingActionListener.java:55)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:619)
    je suis debutante en hibernate et j'ai l'exception suivant et j'ai pas pu parvenir à trouver une solution
    Pouvez vous m'aider svp et merci d'avance

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Peut-on voir les codes qui vont avec?

    A+.

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Autre

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2016
    Messages : 17
    Points : 8
    Points
    8
    Par défaut
    Citation Envoyé par andry.aime Voir le message
    Bonjour,

    Peut-on voir les codes qui vont avec?

    A+.
    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
     
    	@Override
    	public void addTacheemploye(Tacheemploye tacheemploye) {
    		Transaction trns = null;
    		Session session = HibernateUtil.getSessionFactory().openSession();
     
    		try {
    			session.clear();
    			trns = session.beginTransaction();
    			session.save(tacheemploye);
    			session.getTransaction().commit();
    		} catch (RuntimeException e) {
    			if (trns != null) {
    				trns.rollback();
    			}
    			e.printStackTrace();
    		} finally {
    			session.close();
    		}
     
    	}
    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
    @Entity
    @Table(name = "TACHEEMPLOYE")
    public class Tacheemploye implements java.io.Serializable {
    	@Id
    	@Column(name = "idtache" )
    	@GeneratedValue(strategy=GenerationType.IDENTITY)
    	private int idtache;
     
    	private Employe employe;
    	private Projet projet;
    	private String descriptiontache;
    	private Date datedebutparticipation;
    	private Date datefinparticipation;
     
    	public Tacheemploye() {
    	}
     
    	public Tacheemploye(int idtache) {
    		this.idtache = idtache;
    	}
     
    	public Tacheemploye(int idtache, Employe employe, Projet projet,
    			String descriptiontache, Date datedebutparticipation,
    			Date datefinparticipation) {
    		this.idtache = idtache;
    		this.employe = employe;
    		this.projet = projet;
    		this.descriptiontache = descriptiontache;
    		this.datedebutparticipation = datedebutparticipation;
    		this.datefinparticipation = datefinparticipation;
    	}
     
    	@Id
    	@Column(name = "IDTACHE", unique = true, nullable = false, precision = 22, scale = 0)
    	public int getIdtache() {
    		return this.idtache;
    	}
     
    	public void setIdtache(int idtache) {
    		this.idtache = idtache;
    	}
     
    	@ManyToOne(fetch = FetchType.EAGER)
    	@JoinColumn(name = "CIN")
    	public Employe getEmploye() {
    		return this.employe;
    	}
     
    	public void setEmploye(Employe employe) {
    		this.employe = employe;
    	}
     
    	@ManyToOne(fetch = FetchType.EAGER)
    	@JoinColumn(name = "IDPROJET")
    	public Projet getProjet() {
    		return this.projet;
    	}
     
    	public void setProjet(Projet projet) {
    		this.projet = projet;
    	}
     
    	@Column(name = "DESCRIPTIONTACHE", length = 4000)
    	public String getDescriptiontache() {
    		return this.descriptiontache;
    	}
     
    	public void setDescriptiontache(String descriptiontache) {
    		this.descriptiontache = descriptiontache;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "DATEDEBUTPARTICIPATION", length = 7)
    	public Date getDatedebutparticipation() {
    		return this.datedebutparticipation;
    	}
     
    	public void setDatedebutparticipation(Date datedebutparticipation) {
    		this.datedebutparticipation = datedebutparticipation;
    	}
     
    	@Temporal(TemporalType.DATE)
    	@Column(name = "DATEFINPARTICIPATION", length = 7)
    	public Date getDatefinparticipation() {
    		return this.datefinparticipation;
    	}
     
    	public void setDatefinparticipation(Date datefinparticipation) {
    		this.datefinparticipation = datefinparticipation;
    	}
     
    }

  4. #4
    Membre chevronné 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
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    au lieu de :
    mets plutôt
    Eric

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Autre

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2016
    Messages : 17
    Points : 8
    Points
    8
    Par défaut
    salut mercii jeffray03 , null m'a posé un probleme je l'ai remplacer par 0 dans le que tu m'a donné (idtache est int) mais ca m'a pas marché :/

  6. #6
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    Ce-là veut dire que c'est la base de données qui se charge de générer cette colonne. Donc tu ne dois pas affecter une valeur a l'attribut idtache comme ce que tu fais. Vire les lignes:
    this.idtache = idtache; des constructeurs.

    Si t'aurais d'autre erreur, montre nous comment la table TACHEEMPLOYE a été créée.

    A+.

  7. #7
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Autre

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2016
    Messages : 17
    Points : 8
    Points
    8
    Par défaut
    Citation Envoyé par andry.aime Voir le message

    Si t'aurais d'autre erreur, montre nous comment la table TACHEEMPLOYE a été créée.

    A+.
    salut , id est auto increment à travers une sequence, voila comment j'ai crée la table
    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
     
     
     
    CREATE TABLE  "TACHEEMPLOYE" 
       (	"IDTACHE" NUMBER, 
    	"CIN" NUMBER, 
    	"IDPROJET" NUMBER, 
    	"DESCRIPTIONTACHE" VARCHAR2(4000), 
    	"DATEDEBUTPARTICIPATION" DATE, 
    	"DATEFINPARTICIPATION" DATE, 
    	"EMPLOYE" RAW(255), 
    	"PROJET" RAW(255), 
    	 CONSTRAINT "TACHEEMPLOYE_PK" PRIMARY KEY ("IDTACHE") ENABLE, 
    	 CONSTRAINT "TACHEEMPLOYE_FK2" FOREIGN KEY ("IDPROJET")
    	  REFERENCES  "PROJET" ("IDPROJET") ENABLE, 
    	 CONSTRAINT "TACHEEMPLOYE_FK" FOREIGN KEY ("CIN")
    	  REFERENCES  "EMPLOYE" ("CIN") ENABLE
       )

  8. #8
    Membre chevronné 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
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    si tu as une sequence alors tu devras modifier ton entité de cette façon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
    Entity
    @Table(name = "TACHEEMPLOYE")
    public class Tacheemploye implements java.io.Serializable {
    	@Id
    	@Column(name = "idtache" )
    	@GeneratedValue(generator="my_seq")
            @SequenceGenerator(name="my_seq",sequenceName="MY_SEQ", allocationSize=1)
    	private Long idtache;
    tu remplaceras MY_SEQ par le nom exact de ta sequence.

    Eric

Discussions similaires

  1. Réponses: 6
    Dernier message: 10/06/2012, 00h16
  2. Réponses: 1
    Dernier message: 09/11/2010, 15h25
  3. Réponses: 0
    Dernier message: 25/08/2009, 15h32
  4. Réponses: 7
    Dernier message: 01/10/2008, 10h48
  5. premier exemple hibernate: org.hibernate.MappingException
    Par info_plus dans le forum Hibernate
    Réponses: 3
    Dernier message: 26/03/2008, 12h31

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