S7027 False positive on JPA/Hibernate relationships

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.

Hi @javanegmond,

Thank you for creating a new thread.

As mentioned on the other thread where you commented, we are aware of the flaw of this rule, but it is unlikely we will work on improving it soon.

Instead, we are taking slightly different approach in our architecture analysis, so keep an eye on the future releases.

Looking forward to hear your feedback!

All the best,
Irina