Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA ManytoMany Relationship "JoinColumn cannot be resolved to a type" error

I am using Spring boot and trying to implement many to many relationship between User and Skill. I have a table users_skills with columns user_id and skill_id. I keep getting "JoinColumn cannot be resolved to a type" error in @JoinColumn annotations in STS when trying to implement the relationship. Below is my User class

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


@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String email;
private String firstName;
private String lastName;
private List<Skill> skills = new ArrayList<Skill>();



protected User() {}

public User(String email,String firstName, String lastName) {
    this.email = email;
    this.firstName = firstName;
    this.lastName = lastName;
}    


public Long getId() {
    return this.id;
}

public void setId(Long id) {
    this.id = id ;
}

public String getEmail() {
    return this.email;
}

public void setEmail(String email) {
    this.email = email ;
}


public String getFirstName() {
    return this.firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName ;
}

public String getLastName() {
    return this.lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName ;
}

@ManyToMany
@JoinTable(name="users_skills", 
            joinColumns={@JoinColumn(name="user_id")},              
          inverseJoinColumns={@JoinColumn(name="skill_id")})    
public List<Skill> getSkills(){
    return skills;
}

public void setSkills(List<Skill> skills) {
    this.skills = skills ;
}

}
like image 792
geoandri Avatar asked Nov 13 '15 15:11

geoandri


1 Answers

Just write this at the head of your class

import javax.persistence.JoinColumn;

Sometime eclipse doesn't show the link to import it in context menu, but it's there. Hope it will help someone.

like image 73
Cedriga Avatar answered Sep 28 '22 12:09

Cedriga