As requested in Advanced Class Cycle Detection for Java , using a bidirectionally mapped JPA relation currently causes S7027 to raise an issue, while it is commonly agreed on that it’s a good practice for Entity classes.
Another topic was opened about this, but since it’s not reported as a false negative here, it might not get seen: Sonar Cloud rule - S7027 preventing from using JPA/Hibernate Associations
Here’s a reduced example:
@Entity(name = "customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "customer")
private List<Order> orders;
}
@Entity(name = "order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "details")
String details;
@ManyToOne
@JoinColumn(name = "customer_id", referencedColumnName = "id")
private Customer orderedBy;
}
My team is currently using SonarQube Developer Edition v2025.3 (108892). As per Advanced Class Cycle Detection for Java , this issue is said to be fixed in v2025.1, but it is not.