mercredi 19 octobre 2022

My annotation created with reflection API return null even when there is data

so I'm building ORM Manager from scratch with reflection API, everything works fine but there is one annotation @Table that i created and it doesn't want to work as it should. So annotation looks like this

@Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.TYPE)
   public @interface Table {
    String value() default "";
}

and I'm using it on my model class as so

@Entity
@Table(value = "Books")
public class Book {

and now i'm trying to get that value passed as a parameter like this

@Override
    void register(Class... entityClasses) throws SQLException {
        for (Class entityClass : entityClasses) {

            if (entityClass.isAnnotationPresent(Entity.class)) {

                String tableName;

                if (entityClass.isAnnotationPresent(Table.class)) {
                    tableName = entityClass.getClass().getDeclaredAnnotation(Table.class).value();
                } else {
                    tableName = entityClass.getSimpleName();
                }

Dont mind @Entity annotation it works fine. Only problem is that @Table annotation always returns null so it throws NullPointerException and crashing.

Where is a problem, how can i solve this. I already implemented @Column annotation and when i use .value() on @Column annotation it works fine so no clue why it doesn't work for @Table





Aucun commentaire:

Enregistrer un commentaire