2

Does micronaut-data support enum fields?

I tried creating enum field resulted in error. Added type converter using Micronaut TypeConverter framework but still same error that it states

java.lang.NoSuchMethodError: 'void company.SyncRun.setStatus(java.lang.String)' where SyncRun.status is enum field which has converter like below.

@Factory
class TypeConverters {

  @Singleton
  fun syncStatusToString(): TypeConverter<SyncStatus, String> {
    return TypeConverter { value, targetType, context -> Optional.of(value.name) }
  }

  @Singleton
  fun stringToSyncStatus(): TypeConverter<String, SyncStatus> {
    return TypeConverter { value, targetType, context -> Optional.of(SyncStatus.valueOf(value)) }
  }
}

metasync
  • 338
  • 1
  • 10

1 Answers1

2

With JPA you should simply annotate the enum property with @Enumerated(EnumType.STRING).

With JDBC it is working out of the box.

Sascha Frinken
  • 3,134
  • 1
  • 24
  • 27
  • Hi @sascha-frinken what do you mean by "JDCB it is working OOB"? I have ` @Column(name = "content_type") private ContentType contentType; ` and I'm getting: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.SessionFactory]: Schema-validation: wrong column type encountered in column [content_type] in table [document]; found [content_type (Types#VARCHAR)] but expecting [int4 (Types#INTEGER)] – dcalap Apr 13 '23 at 13:00