|
3 | 3 | import java.lang.annotation.Annotation; |
4 | 4 | import java.lang.reflect.Field; |
5 | 5 | import java.lang.reflect.Method; |
| 6 | +import java.lang.reflect.ParameterizedType; |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.Arrays; |
6 | 9 | import java.util.Collection; |
| 10 | +import java.util.List; |
7 | 11 | import java.util.Map; |
| 12 | +import java.util.Optional; |
| 13 | + |
| 14 | +import javax.persistence.Column; |
| 15 | +import javax.persistence.Id; |
| 16 | +import javax.persistence.Table; |
8 | 17 |
|
9 | 18 | import org.apache.commons.lang3.ClassUtils; |
| 19 | +import org.apache.commons.lang3.StringUtils; |
10 | 20 | import org.slf4j.Logger; |
11 | 21 | import org.slf4j.LoggerFactory; |
12 | 22 |
|
@@ -496,13 +506,16 @@ public String getFirstEnumValue(String className) { |
496 | 506 | * |
497 | 507 | * @param className |
498 | 508 | * full qualified class name |
499 | | - * @return the annotated table name if existed or null |
| 509 | + * @return the annotated table name if existed or class name without the word Entity |
500 | 510 | */ |
501 | 511 | public String getEntityTableName(String className) { |
502 | 512 | try { |
503 | 513 | Class<?> entityClass = Class.forName(className); |
504 | 514 | Table table = entityClass.getAnnotation(Table.class); |
505 | | - return table.name(); |
| 515 | + return table == null |
| 516 | + ? StringUtils.left(entityClass.getSimpleName(), |
| 517 | + entityClass.getSimpleName().length() - "Entity".length()) |
| 518 | + : table.name(); |
506 | 519 | } catch (ClassNotFoundException e) { |
507 | 520 | LOG.error("{}: Could not find {}", e.getMessage(), className); |
508 | 521 | return null; |
|
0 commit comments