aileftech / snap-admin

A plug-and-play, auto-generated CRUD database admin panel for Spring Boot apps
MIT License
260 stars 20 forks source link

Support for UUID type #13

Closed zalabbad closed 1 year ago

zalabbad commented 1 year ago

First, thank you for this awesome project!

When I tried to run the app after adding the dependency and its configuration I got the error shown below. I believe it's related to the UUID type. Could you please add the support for UUID types?

Is the bug at startup before you perform any action? Yes, the app crashed because of the error.

Stacktrace

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbAdmin': Invocation of init method failed
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
    at com.mojadwel.backend.MojadwelBackendApplication.main(MojadwelBackendApplication.java:13)
Caused by: tech.ailef.dbadmin.external.exceptions.DbAdminException: Unsupported field type: class java.util.UUID
    at tech.ailef.dbadmin.external.dbmapping.DbFieldType.fromClass(DbFieldType.java:602)
    at tech.ailef.dbadmin.external.DbAdmin.mapForeignKeyType(DbAdmin.java:348)
    at tech.ailef.dbadmin.external.DbAdmin.mapField(DbAdmin.java:287)
    at tech.ailef.dbadmin.external.DbAdmin.processBeanDefinition(DbAdmin.java:184)
    at tech.ailef.dbadmin.external.DbAdmin.init(DbAdmin.java:107)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMethod.invoke(InitDestroyAnnotationBeanPostProcessor.java:457)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:401)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:219)

@Entity code

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

application.properties I used the same config in docs.

Additional context Spring boot version: 3.1.4 DB: postgres 16.0

aileftech commented 1 year ago

Thanks for reporting this! Yes, this can be added easily, I'll update you.

zalabbad commented 1 year ago

Thank you @aileftech. Appreciate your efforts.

aileftech commented 1 year ago

By the way, I believe you are using version 0.1.4 but if you try 0.1.5 you should just have a warning and can try the application in the meantime (read here for how unsupported field types are handled).

zalabbad commented 1 year ago

Actually it's 0.1.5:

implementation 'tech.ailef:spring-boot-db-admin:0.1.5'

Exactly, I read in the docs that it should work even if it's not supported but it was crashing for some reason.

aileftech commented 1 year ago

Oops. I believe it's an interaction I hadn't considered, because this particular field is also an @Id. I'll ship both fixes, thanks! :)

aileftech commented 1 year ago

Should be fixed now on the main branch!

zalabbad commented 1 year ago

Many thanks! Are you planning to release a new version for this change?

aileftech commented 1 year ago

Sure, it'll be 0.1.6 in the next few days!

aileftech commented 1 year ago

It's online. I'll wait for confirmation to close this issue!

aileftech commented 1 year ago

Hey @zalabbad have you had the chance to try the fix?

aileftech commented 1 year ago

I'm closing this for now, as it seems solved from my tests.