rspec/rules/S2206/java/rule.adoc

48 lines
935 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Entity
public class Person {
@Id
private Long id;
@Column(name="name")
private String fname;
public Long getId() { ... }
public String getFname() { ... }
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]