Skip to content

Commit 1498ffe

Browse files
committed
Fix: ensure name field is truncated to 255 characters before DB insert/update
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent aabb0a2 commit 1498ffe

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/gridsuite/studyconfig/server/entities/diagramgridlayout/diagramlayout/NetworkAreaDiagramLayoutEntity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,19 @@ public class NetworkAreaDiagramLayoutEntity extends AbstractDiagramLayoutEntity
3232

3333
@Column(name = "name")
3434
String name;
35+
36+
// Maximum length for the name field
37+
private static final int MAX_NAME_LENGTH = 255;
38+
/**
39+
* Ensures that the name does not exceed the maximum length.
40+
* This method is called before persisting or updating the entity.
41+
*/
42+
@PrePersist
43+
@PreUpdate
44+
private void truncateName() {
45+
if (name != null && name.length() > MAX_NAME_LENGTH) {
46+
name = name.substring(0, MAX_NAME_LENGTH);
47+
}
48+
}
49+
3550
}

0 commit comments

Comments
 (0)