Using hibernate-core 6.4.4.final query is going in infinite loop

56 Views Asked by At

I have below entities, it was working absolutely fine in Spring boot 2.5.14 and Hibernate 5.6.10.final. We're upgrading our application to latest Spring boot 3.2.3 and Hibernate 6.6.4.final.

@Entity
@Table(name = "FOO_TABLE")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
public class FooEntity implements Serializable {

    // other properties

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "key.foo", cascade = CascadeType.ALL, orphanRemoval = true)
    private final Set<BarEntity> barEntities = new HashSet<>();
    
    // other properties

}
@Entity
@Table(name = "BAR_TABLE")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = false)
public class BarEntity implements Serializable {
    
    @EmbeddedId
    private BarEntityKey key;
    
    // other properties
}
@Embeddable
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BarEntityKey implements Serializable {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FOO_UID")
    private FooEntity foo;
    
    // other properties
    
}

pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>6.6.4.final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>6.6.4.final</version>
</dependency>

I tried with

  1. @JsonIgnoreProperties,
  2. @JsonBackReferenceand @JsonManagedReference

Nothing worked, also question is as it was working till Hibernate 5.6.10.final and not working in any version of Hibernate 6.x.x

0

There are 0 best solutions below