-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @OneToMany returns not all records from db
PostPosted: Tue Sep 12, 2017 3:48 pm 
Newbie

Joined: Fri May 26, 2017 10:59 am
Posts: 4
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?


Top
 Profile  
 
 Post subject: Re: @OneToMany returns not all records from db
PostPosted: Mon Sep 18, 2017 7:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Maybe they were never saved. Check what you have in DB as well. The best thing to do is to start logging all SQL statements and see what happens behind the scenes. Check out this article for more details about the best way to do that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.