Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA @OneToMany mappedBy attribute error resolving

I have a little problem with @OneToMany(mappedBy = "table_name") annotations in JPA. So we have 2 tables (all details on screenshot) I added a datasource, but i still have error "Cannot resolve attribute"

Can i resolve it some way?

@Id
@Column(name = "state_id")
public int getStateId() {
    return stateId;
}

public void setStateId(int stateId) {
    this.stateId = stateId;
}

@Basic
@Column(name = "description")
public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

@Basic
@Column(name = "systemname")
public String getSystemName() {
    return systemName;
}

public void setSystemName(String systemname) {
    this.systemName = systemname;
}

@OneToMany(mappedBy = "note_states")
public Set<Note> getNotes() {
    return notes;
}

public void setNotes(Set<Note> notes) {
    this.notes = notes;
}

My problem

like image 858
Илья Белейчев Avatar asked Oct 23 '25 06:10

Илья Белейчев


1 Answers

The mappedBy attribute value is not supposed to be a table name. It's supposed to be, in a bidirectional association, the name of the attribute in the other entity, that maps the association.

Example:

public class Country {
    // ...

    @OneToMany(mappedBy = "parentCountry");
    private Set<City> cities;
}

public class City {
    // ...

    @ManyToOne
    @JoinColomn(name = "country_id")
    private Country parentCountry;
}
like image 194
JB Nizet Avatar answered Oct 24 '25 21:10

JB Nizet