Search code examples
javahibernatejpaintellij-idea

Cannot resolve column 'account_id'


Like pictures, I can't set name for column I use Hibernate 6.4.4

I'm trying to create a relationship between Account and Person but I get the error "Cannot resolve column 'accound_id' ", I've done the mapping but still get the above error.

<mapping class="com.bravos2k5.models.Account"/>
<mapping class="com.bravos2k5.models.Person"/>

Account class: @Entity public class Account {

@Getter
@Setter
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Getter
@Setter
@Column(nullable = false, unique = true, updatable = false)
private String username;

@Getter
@Setter
@Column(nullable = false)
private String password;

@Getter
@Setter
@Column(unique = true)
private String email;

@Getter
@Setter
@Column(unique = true)
private String phone;

@Getter
@Setter
@OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
private List<Person> personList = new ArrayList<>();

private Boolean isBan;

public void setBan(Boolean isBan) {
    this.isBan = isBan;
}

public Boolean isBan() {
    return isBan;
}

public Account() {}

public Account(String username, String password, String email, String phone, Boolean isBan) {
    this.username = username;
    this.password = password;
    this.email = email;
    this.phone = phone;
    this.isBan = isBan;
}

public Account(String username) {
    this.username = username;
}

}

Person class:

@Entity
@Getter
@Setter
public class Person {
    public static boolean FEMALE = false;
    public static boolean MALE = true;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;

    private Boolean gender;

    @ManyToOne
    @JoinColumn(name = "account_id") // Problem here
    private Account account;
    
    public Person() {
    
    }
}

Pls help me resolve this problem


Solution

  • you can try this code in Person class.

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "account_id", referencedColumnName = "id")
    private Account account;