@ManyToOne lazy loading gives null value for child object

I have composed the following code for an entity. While fetching data for the ParentEntity from the database, I successfully obtain the value of parentEntity. However, when attempting to retrieve the childEntity value from the parentEntity, I am encountering a null value(parentEntity.getChildEntity() gives null but it shouldn’t as given child entity exist in DB). It is worth noting that the child_entity_id does exist in the database. As a result, the value of parentEntity.getChildEntity() should not be null. I have attempted various solutions, but unfortunately, none of them have proven effective. I would greatly appreciate your assistance in resolving this issue. Thank you in advance.

@Entity
@Table(name = "parent_entity")
@Getter
@Setter
@ToString
public class ParentEntity implements Serializable {

    private static final long serialVersionUID = -6607515891184993053L;

    public ParentEntity() {
    }

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name = "id", unique = true, nullable = false, length = 40)
    private String id;

    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "child_entity_id")
    private ChildEntity childEntity;
	}
	
	
@Entity
@Table(name = "child_entity")
@Builder(toBuilder = true)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ChildEntity implements Serializable {

    private static final long serialVersionUID = -1105051641140339940L;

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name = "[ID]", unique = true, nullable = false, length = 40)
    private String id;

    @Builder.Default
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "childEntity")
    private Set<ParentEntity> parentEntity = new HashSet<>();
	}

Please let me know if you need further assistance or clarification.
P.S. I have tried with FetchType.EAGER it is working but affecting the performance

Which Hibernate version are you using? Did you try updating to the latest version yet? If so, and the problem persists, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

Thank you for your reply.

I have tried the latest Hibernate version, but the issue still persists. Sometimes it works, but other times it doesn’t, even with accurate DB data. It’s exhibiting strange behavior.

hello , i have the same issue . Did you find the reason why is that happening ?