-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: probleme persister un objet qui contien many-to-one relation
PostPosted: Sat Nov 27, 2010 6:44 pm 
Newbie

Joined: Sat Nov 27, 2010 6:35 pm
Posts: 1
voila le fichier HBM


Code:
<hibernate-mapping>
    <class name="ma.caciopee.elearning.classes.Takes" table="takes" schema="public">
        <composite-id name="id" class="ma.caciopee.elearning.classes.TakesId">
            <key-property name="uid" type="long">
                <column name="uid" length="24"  />
            </key-property>
            <key-property name="eid" type="long">
                <column name="eid" length="24" />
            </key-property>
        </composite-id>
        <many-to-one name="exam" class="ma.caciopee.elearning.classes.Exam" update="false" insert="false" fetch="select">
            <column name="eid" length="254" not-null="true" />
        </many-to-one>
        <many-to-one name="candidat" class="ma.caciopee.elearning.classes.Users" update="false" insert="false" fetch="select">
            <column name="uid" length="24" not-null="true" />
        </many-to-one>
        <property name="answered" type="java.lang.Integer">
            <column name="answered" />
        </property>
        <property name="unanswered" type="java.lang.Integer">
            <column name="unanswered" />
        </property>
        <property name="correct" type="java.lang.Integer">
            <column name="correct" />
        </property>
        <property name="incorrect" type="java.lang.Integer">
            <column name="incorrect" />
        </property>
        <property name="status" type="java.lang.Integer">
            <column name="status" />
        </property>
        <property name="takendate" type="date">
            <column name="takendate" length="64" sql-type="date"/>
        </property>
    </class>
</hibernate-mapping>


voila le POJO associé
Code:

private static final long serialVersionUID = 1L;
   private TakesId id;
   private Exam exam;
   private Users candidat;
   private Integer answered;
   private Integer unanswered;
   private Integer correct;
   private Integer incorrect;
   private Integer status;
   private Date takendate;

   public Takes() {
   }

   public Takes(TakesId id, Exam exam, Users candidat) {
      this.id = id;
      this.exam = exam;
      this.candidat = candidat;
   }

   public Takes(TakesId id, Exam exam, Users candidat, Integer answered,
         Integer unanswered, Integer correct, Integer incorrect,
         Integer status, Date takendate) {
      this.id = id;
      this.exam = exam;
      this.candidat = candidat;
      this.answered = answered;
      this.unanswered = unanswered;
      this.correct = correct;
      this.incorrect = incorrect;
      this.status = status;
      this.takendate = takendate;
   }

   public TakesId getId() {
      return this.id;
   }

   public void setId(TakesId id) {
      this.id = id;
   }

   public Exam getExam() {
      return this.exam;
   }

   public void setExam(Exam exam) {
      this.exam = exam;
   }

   public Users getCandidat() {
      return this.candidat;
   }

   public void setCandidat(Users candidat) {
      this.candidat = candidat;
   }

   public Integer getAnswered() {
      return this.answered;
   }

   public void setAnswered(Integer answered) {
      this.answered = answered;
   }

   public Integer getUnanswered() {
      return this.unanswered;
   }

   public void setUnanswered(Integer unanswered) {
      this.unanswered = unanswered;
   }

   public Integer getCorrect() {
      return this.correct;
   }

   public void setCorrect(Integer correct) {
      this.correct = correct;
   }

   public Integer getIncorrect() {
      return this.incorrect;
   }

   public void setIncorrect(Integer incorrect) {
      this.incorrect = incorrect;
   }

   public Integer getStatus() {
      return this.status;
   }

   public void setStatus(Integer status) {
      this.status = status;
   }

   public Date getTakendate() {
      return this.takendate;
   }

   public void setTakendate(Date date) {
      this.takendate = date;
   }

}




voila le code pour enregistrer le l'objet
Code:

public String save()
   {
      Takes takes= new Takes();
      
      takes.setCandidat(this.currentUser);
      takes.setExam(this.ex);
      
      takes.setCorrect(this.correct);
      takes.setAnswered(this.answered);
      takes.setIncorrect(incorrect);
      takes.setUnanswered(unanswered);
      TakesId tid= new TakesId();
      tid.setEid(this.ex.getEid());
      tid.setUid(this.currentUser.getUid());
      
      takes.setStatus(0);
      
      
      takes.setTakendate(new Date());
      
     takesService.EnregistrerOuModifier(takes);   
      
      return "done";
   }




et voila l'erreur


Caused by: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:624)
at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:789)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:663)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
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 $Proxy11.save(Unknown Source)
at ma.caciopee.elearning.classes.service.TakesServiceImpl.enregistrerTakes(TakesServiceImpl.java:39)
at ma.caciopee.elearning.presentation.classes.FinishView.save(FinishView.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
... 36 more
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:251)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1004)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:342)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:136)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
... 52 more
Caused by: java.sql.BatchUpdateException: L'élément du batch 0 insert into public.takes (answered, unanswered, correct, incorrect, status, takendate, uid, eid) values (2, 0, 2, 0, 0, 2006-01-25 +00:00:00, 1, 1) a été annulé. Appeler getNextException pour en connaître la cause.
at
org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2534)


j'espere avoir une reponse le plus vite possible Merci a tous


Top
 Profile  
 
 Post subject: Re: probleme persister un objet qui contien many-to-one relation
PostPosted: Fri Apr 01, 2011 2:59 am 
Newbie

Joined: Thu Mar 31, 2011 4:37 am
Posts: 11
Comme le message d'erreur l'indique, il s'agit plus que probablement d'une erreur de violation de contrainte sur ta table.
Vérifie les contraintes actives, vérifie que la clé primaire utilisée n'est pas déjà présente dans un autre enregistrement, ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.