mardi 5 octobre 2021

Get table name from annotation with Reflection API

I have the Entity

@Entity
@Table(name = "students")
public class Student {

@Id
@Column(name = "student_id")
private int id;

I have already done getting columns from annotations

ConnectionFactory connectionFactory = new ConnectionFactory();
Connection connection = connectionFactory.connectToDatabase();

default <S extends T> S save(S entity) {
for (Field field : entity.getClass().getDeclaredFields()) {
        Column column = field.getAnnotation(Column.class);
        if (column != null) {
            System.out.println((column.name()));
        }

    }

And now I also need to get table name from this line @Table(name = "students")

How can I get it?





Aucun commentaire:

Enregistrer un commentaire