Affects PMD Version: 6.43.0
Rule: UnusedPrivateField
Description:
Optimistic locking for JPA requires a field annotated with @javax.persistence.Version
. These fields rarely have a getter or setter. Please fix UnusedPrivateField
to ignore fields annotated with @javax.persistence.Version
.
Code Sample demonstrating the issue:
@Entity
@Table(name = "my_table")
public class MyTable implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
private long m_id;
// other fields
@Version
@Column(name = "optimistic_lock", nullable = false)
private short m_optimisticLock; // PMD Violation: UnusedPrivateField
/*
* For JPA
*/
public MyTable()
{
// nothing to do
}
public long getId()
{
return m_id;
}
// getters and setters for other fields except m_optimisticLock
}
Expected outcome:
PMD reports a violation at line private short m_optimisticLock; // PMD Violation: UnusedPrivateField
, but that's wrong. That's a false positive.
Running PMD through: Eclipse PMD Plugin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4