-->
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: Error in embeding two same components
PostPosted: Thu Sep 24, 2009 8:17 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
Code:
public class Order implements java.io.Serializable {

   @Embedded
   @AttributeOverrides( {
         @AttributeOverride(name = "address", column = @Column(name = "shipaddress")),
         @AttributeOverride(name = "city", column = @Column(name = "shipcity")),
         @AttributeOverride(name = "country", column = @Column(name = "shipcity")),
         @AttributeOverride(name = "phone", column = @Column(name = "shipphone")),
         @AttributeOverride(name = "state", column = @Column(name = "shipstate")),
         @AttributeOverride(name = "zip", column = @Column(name = "shipzip")) })
   private Address shipAddress;

   @Embedded
   @AttributeOverrides( {
         @AttributeOverride(name = "address", column = @Column(name = "billaddress")),
         @AttributeOverride(name = "city", column = @Column(name = "billcity")),
         @AttributeOverride(name = "country", column = @Column(name = "billcity")),
         @AttributeOverride(name = "phone", column = @Column(name = "billphone")),
         @AttributeOverride(name = "state", column = @Column(name = "billstate")),
         @AttributeOverride(name = "zip", column = @Column(name = "billzip")) })
   private Address billAddress;
...
}

And I get the following error:
Quote:
org.hibernate.MappingException: Repeated column in mapping for entity: com.abc.xyz.domain.Order column: address (should be mapped with insert="false" update="false")
...

After some research, but haven't found a solution yet. How to solve this problem?


Top
 Profile  
 
 Post subject: Re: Error in embeding two same components
PostPosted: Mon Sep 28, 2009 1:57 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
The embedded component is the following:
Code:
@Embeddable
public class Address implements java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -8131307911307554372L;

   private String addr; // Address details

   private String city; // City

   private String country; // Country code

   private String phone; // Phone number-free format

   private String state; // State

   private String zip; // Zip code

   /**
    * Default constructor, takes no arguments
    */
   public Address() {
   }

   /**
    * Constructor
    */
   public Address(String address, String city, String state, String country,
         String zip, String phone) {
      this.addr = address;
      this.city = city;
      this.state = state;
      this.country = country;
      this.zip = zip;
      this.phone = phone;
   }

   /**
    * Gets the name of the city
    *
    * @return <b>city</b> city name
    */
   @Column(name = "city")
   public String getCity() {

      return city;
   }

   /**
    * Gets the state
    *
    * @return <b>state</b> state name
    */
   @Column(name = "state")
   public String getState() {

      return state;
   }

   /**
    * Gets the country code
    *
    * @return <b>country</b> country code
    */
   @Column(name = "country")
   public String getCountry() {

      return country;

   }

   /**
    * Gets the street address
    *
    * @return <b>address</b> street address
    */
   @Column(name = "address")
   public String getAddr() {

      return addr;
   }

   /**
    * Gets the zip
    *
    * @return <b>zip</b> zip code
    */
   @Column(name = "zip")
   public String getZip() {

      return zip;
   }

   /**
    * Gets the phone
    *
    * @return <b>phone</b> phone number
    */
   @Column(name = "phone")
   public String getPhone() {

      return phone;
   }

   /**
    *
    * Sets the country code
    *
    * @param <b>country</b> country code
    */
   public void setCountry(String country) {
      this.country = country;
   }

   /**
    * Sets the phone number
    *
    * @param <b>phone</b> phone number
    */
   public void setPhone(String phone) {
      this.phone = phone;
   }

   /**
    *
    * Sets the city
    *
    * @param <b>city</b> city name
    */
   public void setCity(String city) {
      this.city = city;
   }

   /**
    * Sets the zip
    *
    * @param <b>zip</b> zip code
    */
   public void setZip(String zip) {
      this.zip = zip;
   }

   /**
    * Sets the street address
    *
    *
    * @param <b>address</b> address
    */
   public void setAddr(String address) {
      this.addr = address;
   }

   /**
    * Sets the state
    *
    * @param <b>state</b> state name
    */
   public void setState(String state) {
      this.state = state;
   }

   /*
    * (non-Javadoc)
    *
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((addr == null) ? 0 : addr.hashCode());
      result = prime * result + ((city == null) ? 0 : city.hashCode());
      result = prime * result + ((country == null) ? 0 : country.hashCode());
      result = prime * result + ((phone == null) ? 0 : phone.hashCode());
      result = prime * result + ((state == null) ? 0 : state.hashCode());
      result = prime * result + ((zip == null) ? 0 : zip.hashCode());
      return result;
   }

   /*
    * (non-Javadoc)
    *
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      Address other = (Address) obj;
      if (addr == null) {
         if (other.addr != null)
            return false;
      } else if (!addr.equals(other.addr))
         return false;
      if (city == null) {
         if (other.city != null)
            return false;
      } else if (!city.equals(other.city))
         return false;
      if (country == null) {
         if (other.country != null)
            return false;
      } else if (!country.equals(other.country))
         return false;
      if (phone == null) {
         if (other.phone != null)
            return false;
      } else if (!phone.equals(other.phone))
         return false;
      if (state == null) {
         if (other.state != null)
            return false;
      } else if (!state.equals(other.state))
         return false;
      if (zip == null) {
         if (other.zip != null)
            return false;
      } else if (!zip.equals(other.zip))
         return false;
      return true;
   }


I shouldn't amp the columns on the embedded object.


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.