E
E
Eugene2017-08-12 18:09:26
Java
Eugene, 2017-08-12 18:09:26

How to make mapping for classes in Spring?

There is a User class

@Entity
@Table(name = "users")
public class User {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer userId;

  @OneToMany(mappedBy = "creator")
  Set<Proposal> creatorsProposal;

  @OneToMany(mappedBy = "performer")
  Set<Proposal> performersProposal;
}

And the Proposal class
@Entity
@Table(name = "proposals")
public class Proposal {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  @ManyToOne
  @JoinColumn(name = "userId")
  @NotNull
  private User creator;
 
  @ManyToOne
  @JoinColumn(name = "userId")
  private User performer;

I am getting the following error
Repeated column in mapping for entity: Proposal column: user_id (should be mapped with insert="false" update="false")

How to make mapping for this scheme correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Oparin, 2017-08-12
@Jek_Rock

@JoinColumn must contain different columns, for example
@JoinColumn(name = "creatorUserId") and @JoinColumn(name = "performerUserId")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question