@Entity
public class DocumentConsolidated {
@Id private UUID id;
@OneToOne(fetch = FetchType.EAGER, optional = false, cascade = CascadeType.ALL)
@JoinColumn(name = "metadata_id")
private DocumentMetadata documentMetadata;
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "documentConsolidated")
private DocumentConfiguration documentConfiguration;
}
@Entity
public class DocumentConfiguration {
@Id private UUID id;
@OneToOne(fetch = FetchType.LAZY)
@MapsId
private DocumentConsolidated documentConsolidated;
}
// Service code:
QDocumentConsolidated qDoc = QDocumentConsolidated.documentConsolidated;
(JPQLQueryFactory) queryFactory
.select(Projections.fields(qDoc, /*qDoc.id, */qDoc.documentConfiguration, qDoc.documentMetadata))
.from(qDoc)
.innerJoin(qDoc.documentConfiguration)
.fetch();
This is only going 2 ways:
- with qDoc.id:
id
is present,documentConfiguration
is null - without qDoc.id:
id
is null,documentConfiguration
is present
Why?
What I already checked: Hibernate query is always bringing documentConfiguration
fields when I run it in a Postgres client. Bot documentMetadata
is present in both cases.