@@ -269,16 +269,16 @@ public static QueryBuilder select(Class<?>... types) {
269269 for (var entry : BeanAdapter .getProperties (type ).entrySet ()) {
270270 var accessor = entry .getValue ().getAccessor ();
271271
272- if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
273- continue ;
274- }
275-
276272 var column = accessor .getAnnotation (Column .class );
277273
278274 if (column == null ) {
279275 continue ;
280276 }
281277
278+ if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
279+ continue ;
280+ }
281+
282282 if (j > 0 && accessor .getAnnotation (ForeignKey .class ) != null ) {
283283 continue ;
284284 }
@@ -385,13 +385,31 @@ public static QueryBuilder selectDistinctIndex(Class<?> type) {
385385 }
386386
387387 private static String getTableName (Class <?> type ) {
388- var table = type .getAnnotation (Table .class );
388+ while (type != null ) {
389+ var table = type .getAnnotation (Table .class );
390+
391+ if (table != null ) {
392+ return table .value ();
393+ }
389394
390- if (table == null ) {
391- throw new UnsupportedOperationException ("Table name is not defined." );
395+ type = getSupertype (type );
392396 }
393397
394- return table .value ();
398+ throw new UnsupportedOperationException ("Table name is not defined." );
399+ }
400+
401+ private static Class <?> getSupertype (Class <?> type ) {
402+ if (type .isInterface ()) {
403+ var interfaces = type .getInterfaces ();
404+
405+ if (interfaces .length > 0 ) {
406+ return interfaces [0 ];
407+ } else {
408+ return null ;
409+ }
410+ } else {
411+ return type .getSuperclass ();
412+ }
395413 }
396414
397415 private static Function <Object , Object > getReadTransform (Method accessor ) {
@@ -507,17 +525,7 @@ private static String getForeignKeyColumnName(Class<?> from, Class<?> to) {
507525 return column .value ();
508526 }
509527
510- if (type .isInterface ()) {
511- var interfaces = type .getInterfaces ();
512-
513- if (interfaces .length > 0 ) {
514- type = interfaces [0 ];
515- } else {
516- type = null ;
517- }
518- } else {
519- type = type .getSuperclass ();
520- }
528+ type = getSupertype (type );
521529 }
522530 }
523531 }
@@ -578,16 +586,16 @@ public static QueryBuilder insert(Class<?> type) {
578586 for (var entry : BeanAdapter .getProperties (type ).entrySet ()) {
579587 var accessor = entry .getValue ().getAccessor ();
580588
581- if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
582- continue ;
583- }
584-
585589 var column = accessor .getAnnotation (Column .class );
586590
587591 if (column == null ) {
588592 continue ;
589593 }
590594
595+ if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
596+ continue ;
597+ }
598+
591599 var primaryKey = accessor .getAnnotation (PrimaryKey .class );
592600
593601 if (primaryKey != null && primaryKey .generated ()) {
@@ -674,16 +682,16 @@ public static QueryBuilder update(Class<?> type) {
674682 for (var entry : BeanAdapter .getProperties (type ).entrySet ()) {
675683 var accessor = entry .getValue ().getAccessor ();
676684
677- if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
678- continue ;
679- }
680-
681685 var column = accessor .getAnnotation (Column .class );
682686
683687 if (column == null ) {
684688 continue ;
685689 }
686690
691+ if (!getTableName (accessor .getDeclaringClass ()).equals (tableName )) {
692+ continue ;
693+ }
694+
687695 if (accessor .getAnnotation (PrimaryKey .class ) != null || accessor .getAnnotation (Final .class ) != null ) {
688696 continue ;
689697 }
0 commit comments