-->
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.  [ 9 posts ] 
Author Message
 Post subject: Caused by: org.hibernate.MappingException: Repeated column i
PostPosted: Fri Feb 13, 2009 9:57 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Hello,

I try to test the sample in the hibernate documentation about annotation :

I have a simple class Adresse :
Code:
@Embeddable
public class Adresse implements Serializable{

   private String adresse;

   private String codePostal;

// ... Getters()/Setters()


And I would like to have two members of adresse in another class :



Code:

@Entity
....class

@Column(name="lieuDepannage")
private Adresse lieuDepannage;

@Column(name="lieuSinistre")
private Adresse lieuSinistre;


I see in documentation when we want at least two embedded object, we need to override at least one default column name.

But it does not work ... ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 10:09 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Hi Louevie,

Your mapping is wrong. As you defined the Address class as Embeddable , so each property of Address class with store in different column. so your mapping
Code:
@Column(name="lieuDepannage")
private Adresse lieuDepannage;



is wrong.

it should be in this way

Code:
@AttributeOverrides({
            @AttributeOverride(name="adresse", column=@Column("adresse")),
            @AttributeOverride(name="codePostal", column=@Column("postal_code"))
    })
private Address lieuDepannage;



same way you can override column defination for another property lieuSinistre


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:08 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Code:

@AttributeOverrides({
      @AttributeOverride(name="villeLieu", column=@Column(name="ville")),
        @AttributeOverride(name="adresseLieu", column=@Column(name="adresse")),
        @AttributeOverride(name="codePostalLieu", column=@Column(name="postal_code"))
   })


I overide like this for the two members with villeOther, etc... But it still does not work... ?[/code]

I have this information in log error :
column: adresse (should be mapped with insert="false" update="false")


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:36 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Could you post code of both class and Error message.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:51 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
This is the code

Code:
@Entity
public class Sinistre implements Serializable{
   
...
   
   @Id
   private long idH;

...   
   
   @AttributeOverrides({
      @AttributeOverride(name="villeLieu", column=@Column(name="ville")),
        @AttributeOverride(name="adresseLieu", column=@Column(name="adresse")),
        @AttributeOverride(name="codePostalLieu", column=@Column(name="postal_code"))
   })
   private Adresse lieuDepannage;
   @Column(name="lieuSinistre")
   @AttributeOverrides({
      @AttributeOverride(name="ville", column=@Column(name="ville")),
        @AttributeOverride(name="adresse", column=@Column(name="adresse")),
        @AttributeOverride(name="codePostal", column=@Column(name="postal_code"))
   })


An this is the log error :
Code:
Exception in thread "main" java.lang.ExceptionInInitializerError
   at project.control.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:108)
   at project.control.Application.getAllFile(Application.java:108)
   at project.control.Application.main(Application.java:80)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: project.model.hibernate.Sinistre column: adresse (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:670)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:692)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:688)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:714)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at projectcontrol.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:101)
   ... 2 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:57 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
i have some question/suggestions ?

Code:
@Entity
public class Sinistre implements Serializable{
   
...
   
   @Id
   private long idH;

...   
   
   @AttributeOverrides({
      @AttributeOverride(name="villeLieu", column=@Column(name="ville")),
        @AttributeOverride(name="adresseLieu", column=@Column(name="adresse")),
        @AttributeOverride(name="codePostalLieu", column=@Column(name="postal_code"))
   })
   private Adresse lieuDepannage;

   @Column(name="lieuSinistre") // REMOVE THIS


   @AttributeOverrides({
// how are you changing the property name,this should be "villeLieu" not "ville". same for others also.
      @AttributeOverride(name="ville", column=@Column(name="ville")),
        @AttributeOverride(name="adresse", column=@Column(name="adresse")),
        @AttributeOverride(name="codePostal", column=@Column(name="postal_code"))
   })


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 11:59 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Thank you very much, it works, it is just a mistake between the @Column value.

Correted :
@AttributeOverrides({
@AttributeOverride(name="ville", column=@Column(name="ville_lieu")),
@AttributeOverride(name="adresse", column=@Column(name="adresse_lieu")),
@AttributeOverride(name="codePostal", column=@Column(name="postal_code_lieu"))
})

I wish you an excellent weekend and thank again !!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 12:01 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Please rate the post , if helps you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 12:02 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Please rate the post , if it helps you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.