35 lines
718 B
Plaintext
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() { ... }
|
|
----
|
|
|