rspec/rules/S2206/java/rule.adoc
2021-04-28 18:08:03 +02:00

35 lines
718 B
Plaintext

Persistence annotations should be marked either on fields or on getters but not on both. Mix the two and the annotated fields will be ignored. The potential results are that your database tables are not created or not populated (and read) correctly.
== Noncompliant Code Example
----
@Entity
public class Person { // Noncompliant; both fields and getters annotated
@Id
private Long id;
private String fname;
public Long getId() { ... }
@Column(name="name")
public String getFname() { ... }
----
== Compliant Solution
----
@Entity
public class Person {
@Id
private Long id;
@Column(name="name")
private String fname;
public Long getId() { ... }
public String getFname() { ... }
----