I have a gigantic entity and I'd like to load its subset (ID and baz property):
@Entity
public class GiganticEntity {
@Id Long id;
@OneToOne(mappedBy = "giganticEntity")
Foo foo;
@OneToOne(mappedBy = "giganticEntity")
Bar bar;
@OneToOne(mappedBy = "giganticEntity")
Baz baz;
// default constructor + getters/setters
public GiganticEntity(Long id, Baz baz) {
this.id = id;
this.baz = baz;
}
}
I tried using following JPA query, but baz property will be null:
"SELECT new package.GiganticEntity(ge.id, ge.baz) " +
"FROM GiganticEntity ge WHERE ge.id = 1";
I tried adding an explicit join, but it resulted in null as well:
"SELECT new package.GiganticEntity(ge.id, b) FROM GiganticEntity ge " +
"LEFT JOIN ge.baz as b " +
"WHERE ge.id = 1";
If I only select my gigantic entity like this then everything works (but I am trying to save some joins):
"SELECT GiganticEntity g WHERE g.id = 1";
Is this achievable with JPA? I am using Hibernate as its implementation.
EDIT: Query actually needs to be LEFT JOIN
, so I need all gigantic entites with baz
-es.