2

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;
    }

}

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

"Welcome to SO. If one of the answers below fixes your issue, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved, and it gives the person that helps you credit for the assist. See here for a full explanation"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.