-->
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: Hibernate mapping exception
PostPosted: Tue Jun 28, 2016 7:10 am 
Newbie

Joined: Mon Jun 27, 2016 8:03 am
Posts: 3
Hello,

I work with spring MVC 3.2.6, Hibernate 4, Eclipse Juno.

I have the following entities PlantillaEncuesta and PlantillaEncuestaPK

PlantillaEncuesta

Code:
/**
* The persistent class for the PLANTILLA_ENCUESTA database table.
*
*/
@Entity
@Table(name="PLANTILLA_ENCUESTA")
public class PlantillaEncuesta implements Serializable {
   private static final long serialVersionUID = 1L;

   @EmbeddedId
   private PlantillaEncuestaPK id;
   
   

   @Lob
   private String contenido;

   //bi-directional many-to-one association to EncuestaSem
   @ManyToOne
   @JoinColumns({
      @JoinColumn(name="ID_ENCUESTA_SEM", referencedColumnName="ENCUESTA_SEM_ID"),
      @JoinColumn(name="SURVEY_ID", referencedColumnName="SURVEY_ID")
      })
   

   private EncuestaSem encuestaSem;

   public PlantillaEncuesta() {
   }

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

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

   public String getContenido() {
      return this.contenido;
   }

   public void setContenido(String contenido) {
      this.contenido = contenido;
   }

   public EncuestaSem getEncuestaSem() {
      return this.encuestaSem;
   }

   public void setEncuestaSem(EncuestaSem encuestaSem) {
      this.encuestaSem = encuestaSem;
   }

}


PlantillaEncuestaPK

Code:
/**
* The primary key class for the PLANTILLA_ENCUESTA database table.
*
*/
@Embeddable
public class PlantillaEncuestaPK implements Serializable {
   //default serial version id, required for serializable classes.
   private static final long serialVersionUID = 1L;

   @Column(name="ID_ENCUESTA_SEM")
   private long idEncuestaSem;

   @Column(name="PLANTILLA_ENCUESTA_ID")
   private long plantillaEncuestaId;

   @Column(name="SURVEY_ID")
   private long surveyId;

   public PlantillaEncuestaPK() {
   }
   public long getIdEncuestaSem() {
      return this.idEncuestaSem;
   }
   public void setIdEncuestaSem(long idEncuestaSem) {
      this.idEncuestaSem = idEncuestaSem;
   }
   public long getPlantillaEncuestaId() {
      return this.plantillaEncuestaId;
   }
   public void setPlantillaEncuestaId(long plantillaEncuestaId) {
      this.plantillaEncuestaId = plantillaEncuestaId;
   }
   public long getSurveyId() {
      return this.surveyId;
   }
   public void setSurveyId(long surveyId) {
      this.surveyId = surveyId;
   }

   public boolean equals(Object other) {
      if (this == other) {
         return true;
      }
      if (!(other instanceof PlantillaEncuestaPK)) {
         return false;
      }
      PlantillaEncuestaPK castOther = (PlantillaEncuestaPK)other;
      return
         (this.idEncuestaSem == castOther.idEncuestaSem)
         && (this.plantillaEncuestaId == castOther.plantillaEncuestaId)
         && (this.surveyId == castOther.surveyId);
   }

   public int hashCode() {
      final int prime = 31;
      int hash = 17;
      hash = hash * prime + ((int) (this.idEncuestaSem ^ (this.idEncuestaSem >>> 32)));
      hash = hash * prime + ((int) (this.plantillaEncuestaId ^ (this.plantillaEncuestaId >>> 32)));
      hash = hash * prime + ((int) (this.surveyId ^ (this.surveyId >>> 32)));
      
      return hash;
   }
}


When I deploy my project, I get the following error

Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: eusurvey.modelA.daos.PlantillaEncuesta column: ID_ENCUESTA_SEM (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:681)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:703)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:725)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:478)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1294)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1736)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
   at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
   at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
   at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
   ... 59 more
:org.hibernate.MappingException:Repeated column in mapping for entity: eusurvey.modelA.daos.PlantillaEncuesta column: ID_ENCUESTA_SEM (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:681)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:703)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:725)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:478)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
   Truncated. see log file for complete stacktrace
>



Where do I have to add insert="false" update="false"?

Thanks in advance

Carlota Vina


Top
 Profile  
 
 Post subject: Re: Hibernate mapping exception
PostPosted: Tue Jun 28, 2016 7:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The error message is pretty clear, so you should change the mapping to this:

Code:
@ManyToOne
@JoinColumns({
  @JoinColumn(name="ID_ENCUESTA_SEM", referencedColumnName="ENCUESTA_SEM_ID", insert=false update=false),
  @JoinColumn(name="SURVEY_ID", referencedColumnName="SURVEY_ID", insert=false update=false)
})


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.