-->
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.  [ 6 posts ] 
Author Message
 Post subject: Composite Key + ManyToOne = Repeated column in mapping
PostPosted: Mon Aug 27, 2007 3:14 pm 
Newbie

Joined: Tue Jul 24, 2007 1:52 pm
Posts: 5
Hibernate version: 3.2.0.ga

Annotations version: 3.3.0.GA

I have a UfDTO with composite key: "estado" and "pais"
"pais" is a manyToOne with PaisDTO.

here are the codes:

UfDTO.java
Code:

@Entity
@IdClass(UfDTO.UfPk.class)
@Table(name="\"unid-feder\"", schema="PUB")
public class UfDTO extends BaseDTO {

   private static final long serialVersionUID = 1L;

   @Id
   private String estado;
   
   @Id
   private PaisDTO pais;

   @Column(name = "\"no-estado\"")
   private String nomeEstado;
   
   public UfDTO(){
   }

   //gets e sets.....
   

   @Embeddable
    private static class UfPk {

        /* Construtores */
       
        public UfPk(String estado, PaisDTO pais) {
           setEstado(estado);
           setPais(pais);
        }

        /* Campos */

        private String estado;
       
        @ManyToOne(fetch = FetchType.EAGER)
       @JoinColumn(name="pais",insertable=false, updatable=false)
       @Fetch(FetchMode.JOIN)
       @Cascade(CascadeType.PERSIST)
       @NotFound(action=NotFoundAction.IGNORE)
        private PaisDTO pais;

   //gets and sets.....
    }
}


PaisDTO.java
Code:

@Entity
@Table(name="pais", schema="PUB")
public class PaisDTO extends BaseDTO {

   private static final long serialVersionUID = 1L;

   @Id
   @Column(name = "\"nome-pais\"")
   private String nomePais;

   @Column(name = "\"nome-compl\"")
   private String nomeComplementar;
   
   @Column(name = "\"cod-internacional-pais\"")
   private Integer codigoInternacional;

   @Column(name = "\"cod-pais\"")
   private Integer codigoPais;

   //gets and sets

}


And i got this error....

Full stack trace of any exception that occurs:
Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: cadastros.modelo.uf.dominio.UfDTO column: pais (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:623)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
   at base.modelo.persistencia.HibernateUtil.<clinit>(HibernateUtil.java:61)


I don't know what i'm doing wrong anymore..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 28, 2007 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
columns in @Id properties (composite or not), cannot have insertable=false updatable=false

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 29, 2007 7:33 am 
Newbie

Joined: Tue Jul 24, 2007 1:52 pm
Posts: 5
emmanuel wrote:
columns in @Id properties (composite or not), cannot have insertable=false updatable=false


you say, make this:
Code:
@Embeddable
    private static class UfPk implements Serializable {

      private static final long serialVersionUID = 1L;

      /* Construtores */
       
        public UfPk(String estado, PaisDTO pais) {
           setEstado(estado);
           setPais(pais);
        }

        /* Campos */

        private String estado;
       
        @ManyToOne(fetch = FetchType.EAGER)
       @JoinColumn(name="pais")
       @Fetch(FetchMode.JOIN)
       @Cascade(CascadeType.PERSIST)
       @NotFound(action=NotFoundAction.IGNORE)
        private PaisDTO pais;

i did and not work too same problem... =/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I mean define insertable=false updatable=false on the other column definition, not the one stored in the composite id.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 8:38 am 
Newbie

Joined: Thu Jul 28, 2005 12:24 pm
Posts: 7
Rosnei wrote:

you say, make this:
Code:
@Embeddable
    private static class UfPk implements Serializable {

      private static final long serialVersionUID = 1L;

      /* Construtores */
       
        public UfPk(String estado, PaisDTO pais) {
           setEstado(estado);
           setPais(pais);
        }

        /* Campos */

        private String estado;
       
        @ManyToOne(fetch = FetchType.EAGER)
       @JoinColumn(name="pais")
       @Fetch(FetchMode.JOIN)
       @Cascade(CascadeType.PERSIST)
       @NotFound(action=NotFoundAction.IGNORE)
        private PaisDTO pais;



I have a mapping like your one and all works fine (with the emmanuel's suggestion).
Just a question.
In your PaisDTO class do you have an @OneToMany relation pointing to the UfPk @ManyToOne definition ?

I've trieded but seems to be impossible because tha corresponding @Id field in the entity class cannot be annotated with @ManyToOne

Best regards

sergio sette


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 9:22 am 
Newbie

Joined: Tue Jul 24, 2007 1:52 pm
Posts: 5
chicco7 wrote:
I have a mapping like your one and all works fine (with the emmanuel's suggestion).

can you post the code? I'm not undestanding what i need to do...

chicco7 wrote:
Just a question.
In your PaisDTO class do you have an @OneToMany relation pointing to the UfPk @ManyToOne definition ?

No, but I do that now and the problem is the same =/

Repeated column in mapping for entity: cadastros.modelo.uf.dominio.UfDTO column: pais (should be mapped with 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.  [ 6 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.