cloudviz
cloudviz

Reputation: 1001

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity

I am beginner on Hibernate.

I am getting this error message and could not figure out what is wrong:

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.hibernate.aris.Subscribers column: city (should be mapped with insert="false" update="false")"

I read somewhere that one has to set the property within the HBM file to "inverse" but I don't really know what that means yet.

Any advice would be appreciated?

Embeddable Class called Address

@Embeddable
public class Address {
    @Column (name = "STREET_NAME")
    private String street;

    @Column (name = "CITY_NAME")
    private String city;

    @Column (name = "POST_CODE")
    private String postcode;

    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getPostcode() {
        return postcode;
    }
    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }
}

Subscribers Class

@Entity
@Table(name = "Subscriberstbl")
public class Subscribers {

    private int subID;
    private String firstname;
    private String lastname;

    @Embedded
    @AttributeOverrides({
    @AttributeOverride(name ="street", column = @Column(name="HOME_STREET_NAME")), 
    @AttributeOverride(name = "city", column = @Column(name="HOME_CITY_NAME")), 
    @AttributeOverride(name = "postcode", column = @Column(name="HOME_POST_CODE"))})
    private Address homeaddress;

    @Embedded
    private Address officeaddress;

    //Getters and Setters
    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    @Id
    @GeneratedValue
    public int getSubID() {
        return subID;
    }
    public void setSubID(int subID) {
        this.subID = subID;
    }

    public Address getOfficeAddress() {
        return officeaddress;
    }

    public void setOfficeAddress(Address address) {
        this.officeaddress = address;
    }

  public Address getHomeaddress() {
        return homeaddress;
    }

    public void setHomeaddress(Address homeaddress) {
        this.homeaddress = homeaddress;
    }

}

Upvotes: 2

Views: 1334

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18383

You are mixing access by FIELD (annotation on field) and by PROPERTY (annotation on accessorss) and PROPERTY is the winner so @AttributesOverride is ignored.
Try move @Id @GeneratedValue from accessor to field class.

Upvotes: 3

Related Questions