Let's say there are two DB tables, say
- Table A with primary key as aId, and
- Table B with primary key as bId.
@Entity
@Table(name = "A")
public class A implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "A_KEY")
private String aId;
@OneToMany(mappedBy=aId)
List<B> b;
}
@Entity
@Table(name = "B")
public class B implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "B_KEY")
private String bId;
@Column(name = "A_KEY")
private String aId;
}
When I retrieve A the first time database is called and I have A and associated B. Now I save this instance of A to some file and read it back. When I say (instance of A)#getB I do not want a DB call as I have the data in in memory with me. How to avoid this DB call.