@SequenceGenerator with Empty Sequence Name
ID |
java.spring_data_empty_sequence_name |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
best-practice, spring |
Description
Reports @SequenceGenerator annotations whose sequenceName attribute is set to an empty string. An empty sequence name causes the persistence provider to fall back to a default naming strategy, which is likely unintended and may collide with other sequence generators in the schema.
Rationale
When sequenceName is explicitly set to "", the provider generates a default sequence name (typically derived from the table or entity name). This defeats the purpose of specifying a sequence generator and can lead to unexpected collisions when multiple entities share the same default sequence.
// Bad: empty sequenceName
@Entity
@SequenceGenerator(name = "order_gen", sequenceName = "")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_gen")
private Long id;
}
Remediation
Provide a meaningful sequence name, or remove the sequenceName attribute entirely to use the provider default intentionally.
// Good: explicit sequence name
@Entity
@SequenceGenerator(name = "order_gen", sequenceName = "order_id_seq")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_gen")
private Long id;
}