problem description
InHibernate @ OneToOne bidirectional association, how does the main table load lazily?
related codes
@Entity
@Table(name = "db_user")
public class User{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@JSONField(serialize=false)
@OneToOne(fetch = FetchType.LAZY,mappedBy = "accountUser")
private Account account;
//get set
}
@Entity
@Table(name = "db_account")
public class Account{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Double money;
@Column(name="user_id",insertable = false,updatable = false)
private Integer userId;
@JSONField(serialize = false)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="user_id")
private User accountUser;
//get set
}
when querying Account, Account.accountUser can be lazily loaded,
but when querying User, User.account executes the query immediately, lazy loading fails.
there is no foreign key association between the two tables in the database. I would like to ask you how to make the lazy loading of User.account effective?