File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
backend/src/main/java/com/park/utmstack/domain/application_modules Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public class UtmModule implements Serializable {
3232 @ Column (name = "pretty_name" )
3333 private String prettyName ;
3434
35- @ Enumerated ( EnumType . STRING )
35+ @ Convert ( converter = com . park . utmstack . domain . application_modules . enums . ModuleNameConverter . class )
3636 @ Column (name = "module_name" )
3737 private ModuleName moduleName ;
3838
Original file line number Diff line number Diff line change 1+ package com .park .utmstack .domain .application_modules .enums ;
2+
3+ import javax .persistence .AttributeConverter ;
4+ import javax .persistence .Converter ;
5+ import org .slf4j .Logger ;
6+ import org .slf4j .LoggerFactory ;
7+
8+ @ Converter (autoApply = true )
9+ public class ModuleNameConverter implements AttributeConverter <ModuleName , String > {
10+ private static final Logger log = LoggerFactory .getLogger (ModuleNameConverter .class );
11+
12+ @ Override
13+ public String convertToDatabaseColumn (ModuleName attribute ) {
14+ return attribute == null ? null : attribute .name ();
15+ }
16+
17+ @ Override
18+ public ModuleName convertToEntityAttribute (String dbData ) {
19+ if (dbData == null ) {
20+ return null ;
21+ }
22+ try {
23+ return ModuleName .valueOf (dbData );
24+ } catch (IllegalArgumentException e ) {
25+ log .warn ("Unknown ModuleName in database: '{}'. Mapping to null to prevent crash. ---" , dbData );
26+ return null ;
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments