Reputation: 988
How everybody solve code smells related to method name on interfaces that extends JpaRepository? In my case I have an CpoWorkflowStepExecution
entity and I want to find by id and date.
CpoWorkflowStepExecution:
@Entity
@Table(name = "cpo_workflow_step_execution", catalog = "cup_orchestrator")
public class CpoWorkflowStepExecution implements java.io.Serializable {
private Integer workflowStepExecutionId;
private CpoWorkflowExecution cpoWorkflowExecution;
private CpoWorkflowStep cpoWorkflowStep;
private LocalDateTime startDate;
private LocalDateTime finishDate;
private String outcome;
...
WorkflowStepExecRep:
@Repository
public interface WorkflowStepExecRep extends JpaRepository<CpoWorkflowStepExecution, Integer>{
Optional<CpoWorkflowStepExecution> findByCpoWorkflowStep_WorkflowStepIdAndFinishDateIsNull(String workflowStepId);
SonarQube: Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
Upvotes: 2
Views: 853
Reputation: 988
I've changed the method name by removing _
character and it worked perfectly with SonarQube and JpaRepository:
findByCpoWorkflowStepWorkflowStepIdAndFinishDateIsNull
Upvotes: 3
Reputation: 31
Spring Data uses _
to resolve ambiguity issues. You can find more details at Working with Spring Data Repository - Property Expressions.
You might want to change Sonarqube's rule java:S100
from ^[a-z][a-zA-Z0-9]*$
to ^[a-z][a-zA-Z0-9]+(_[a-zA-Z]+)*$
but makes it possible to misuse
Upvotes: 1