Using the following entities:
@Entity
public class Foo
{
@Id
private Long id;
@OneToOne(optional = true)
@MapsId
@JoinColumn(name = "id")
@NotFound(action = NotFoundAction.IGNORE)
private Bar bar;
}
@Entity
public class Bar {
@Id
private long barId;
}
If there exists a Foo entity, but there is no Bar entity with the same ID value as the Foo entity, then the following query, "from Foo where bar.id = ?1", should return null. Instead, the query returns a Foo object with property bar set to null. This happens because the generated SQL does not include a join to the Bar entity table, as it should. Notice that the query uses the "generic" ID named "id", not the actual ID (barId). |