I want to model an optional one to one mapping with JPA.
tableA has a column (flag) and when that is true I need to select additional data from an other tableB to get a string.
tableB has a fk to the pk of tableA.
So far I tiered this mapping but hibernates makes additional selects for tableB per default. I only want those when I access the mapping to tableB.
Class TableA
@OneToOne(mappedBy= tableA_id, fetch = FetchType.LAZY, optional = true)
private TableB tableB;
Class TableB
@OneToOne(mappedBy= tableA_id, fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "TABLEA_ID"
private TableA tableA
The result is that I get selects on tableB just from a
em.createQuery("from TableA") before even accessing getTableB().