I have @OneToMany unidirectional relations between entities and when I fetch root entity, it only parts of children.
There are some class structures:
Code:
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "view_frame_input_schema")
@AttributeOverride(name = "id", column = @Column(name = "view_frame_input_schema_key"))
public class ViewFrameInputSchema extends ConcurrencySafeEntity implements Comparable<ViewFrameInputSchema> {
private String name;
private Integer ordering;
@OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "view_frame_input_schema_mapping_key", referencedColumnName = "view_frame_input_schema_mapping_key")
private ViewFrameInputSchemaMapping mapping;
...
Code:
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "view_frame_input_schema_mapping")
@AttributeOverride(name = "id", column = @Column(name = "view_frame_input_schema_mapping_key"))
public class ViewFrameInputSchemaMapping extends ConcurrencySafeEntity {
@OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "path_key", referencedColumnName = "path_key", nullable = false)
private Path path;
Code:
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "path")
@AttributeOverride(name = "id", column = @Column(name = "path_key"))
public class Path extends IdentifiedValueObject {
@OneToMany(cascade = {CascadeType.ALL}, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "path_key", referencedColumnName = "path_key",
nullable = false)
@OrderBy("ordering ASC")
private SortedSet<PathElement> pathElements = new TreeSet<>();
...
Code:
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "path_element")
@AttributeOverride(name = "id", column = @Column(name = "path_element_key"))
public class PathElement extends IdentifiedValueObject implements Comparable<PathElement> {
@AttributeOverride(name = "id", column = @Column(name = "frame_id"))
private AssetId frameId;
@Column(name = "relationship_name")
private String relationshipName;
private Integer ordering;
...
and corresponding tables:
Code:
CREATE TABLE catalog.view_frame_input_schema_mapping
(
view_frame_input_schema_mapping_key bigint NOT NULL,
path_key bigint NOT NULL,
CONSTRAINT pk_view_frame_input_schema_mapping PRIMARY KEY (view_frame_input_schema_mapping_key)
)
CREATE TABLE catalog.path
(
path_key bigint NOT NULL,
CONSTRAINT pk_path PRIMARY KEY (path_key)
)
CREATE TABLE catalog.path_element
(
path_element_key bigint NOT NULL,
path_key bigint NOT NULL,
frame_id character varying(36) COLLATE pg_catalog."default" NOT NULL,
relationship_name character varying(100) COLLATE pg_catalog."default",
ordering smallint NOT NULL,
CONSTRAINT pk_path_element PRIMARY KEY (path_element_key)
)
I store root entity with 3 ViewFrameInputSchemaMapping each of them has corresponding Path with 1, 2 and 3 PathElements - all is ok.
without warnings etc.
But when I read root entity I get these ViewFrameInputSchemaMapping with Path:
- PathElements of the first and second Path are empty!
- Third Path has only 3 records as it should.
Can you advise what might cause the problem?