0

I have this simple code:

String tableName = MyEntity.class.getAnnotation( javax.persistence.Table.class ).name();

But IntelliJ underlines the fact that the method name() does not exist Cannot resolve method "name()".

I also get this error during the compilation:

Error:(29, 68) java: cannot find symbol
  symbol:   method name()
  location: interface java.lang.annotation.Annotation

I saw many example codes using this method, an example here: https://stackoverflow.com/a/1320890/6643803 What am I missing?

Thanks

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
akuma8
  • 4,160
  • 5
  • 46
  • 82

1 Answers1

1

As you can see here there is no name() function inside the Annotation interfaces

You probably need to cast it:

Table table = MyEntity.class.getAnnotation(javax.persistence.Table.class);
String tableName = table.name();
Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48