@Entity
@Table(name = "users")
public class User extends Model
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Long id;
@OneToOne(mappedBy= "user", cascade = {CascadeType.ALL})
@JoinColumn(name="info_id",referencedColumnName = "id")
public Info info;
}
@Entity
@Table(name="infos")
public class Info extends Model
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Long id;
@OneToOne(mappedBy="info",cascade = {CascadeType.ALL})
@JoinColumn(name="user_id", referencedColumnName = "id")
public User user;
}
And in my migration, users
table includes a info_id
column of bigint type, and infos
table includes a user_id
column of bigint type.
However, when i run the application, it gives me PersistenceException: Error with the Join on [models.Info.user]. Could not find the matching foreign key for [id] in table[users]? Perhaps using a @JoinColumn with the name/referencedColumnName attributes swapped?
Can anyone provide some insight into what's wrong in my code and how to fix it? Thank you.