I have two entities: TableA and TableB. When I fetch TableA, TableB is always null. What am I doing wrong?
This is how I am getting it:
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery criteriaQuery = builder.createQuery(TableA.class);
Root from = criteriaQuery.from(TableA.class);
criteriaQuery.select(from);
This is the Query made:
select generatedAlias0 from TableA as generatedAlias0
TableA:
@Entity
@Table(name = “TableA”)
public class TableA implements Serializable {@Id @Column(name = "id", nullable = false) private Integer id = null;
@Id
@Column(name = “active”, nullable = false)
private Integer active = null;private Integer parentId = null;
private String myColA = null;
@OneToOne(fetch = FetchType.EAGER) @JoinColumns({ @JoinColumn(name = "id", referencedColumnName = "parentId"), @JoinColumn(name = "active", referencedColumnName = "active")} ) @Where(clause = "active=1") private TableB TableB = null; private Boolean ignorePlanCutoff = null;
}
TableB:
@Entity
@Table(name = “TableB”)
public class TableB implements Serializable {@Id @Column(name = "id", nullable = false) private Integer id = null;
@Id
@Column(name = “active”, nullable = false)
private Integer active = null;private Integer parentId = null;
private Boolean colB = null;
}
Both these entities have composite IDs, not showing that here for brevity.