3

I am working on hibernate and tying to associate mapping with @OneToMany relationship with composite key. Following are the entities that currently my using .

@Embeddable
@Getter
@Setter
public class AddressKey implements Serializable {

    private static final long serialVersionUID = -307823488229761699L;

    @Column(name = "id")
    private Long id;

    @Column(name = "city")
    private Long city;

    @Column(name = "locale")
    private String locale;

    @Column(name = "type")
    private String type;

    @ManyToOne
    @JoinColumn(name="id")
    private Person person;
}

@Entity
@Table(name = "address", schema = "test")
@Setter
@Getter
public class AddressHistory {

    @EmbeddedId
    private AddressKey key;

    @Column(name = "active")
    private boolean active;

    @Column(name = "current")
    private boolean current;

}


@Entity
@Table(name = "person", schema="test")
@ToString
public class Person {

    @Id
    @Column(name = "id")
    private Long id;

    @OneToMany(mappedBy="key.person", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
    private Set<AddressHistory> addressHistory;
}

But when I am trying to run this program it gives me following error.

repeated column in mapping for entity AddressHistory.

Someone help me to fix this what's wrong in this mapping. Thanks in advance

keepmoving
  • 1,813
  • 8
  • 34
  • 74
  • Possible duplicate of [Another Repeated column in mapping for entity error](https://stackoverflow.com/questions/15076463/another-repeated-column-in-mapping-for-entity-error) – beatrice Mar 30 '19 at 12:54

1 Answers1

0

You repeated columns. Remove @JoinColumn(name="id") in AddressKey since you already have one column with the same name or rename it to something else and more maintainable like person_id.

noname
  • 227
  • 2
  • 7