Skip to content

Commit

Permalink
fix missing import and fix missing table name
Browse files Browse the repository at this point in the history
  • Loading branch information
lilliCao committed Aug 24, 2020
1 parent 1b7a6d1 commit 1d87bb7
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -496,13 +506,16 @@ public String getFirstEnumValue(String className) {
*
* @param className
* full qualified class name
* @return the annotated table name if existed or null
* @return the annotated table name if existed or class name without the word Entity
*/
public String getEntityTableName(String className) {
try {
Class<?> entityClass = Class.forName(className);
Table table = entityClass.getAnnotation(Table.class);
return table.name();
return table == null
? StringUtils.left(entityClass.getSimpleName(),
entityClass.getSimpleName().length() - "Entity".length())
: table.name();
} catch (ClassNotFoundException e) {
LOG.error("{}: Could not find {}", e.getMessage(), className);
return null;
Expand Down

0 comments on commit 1d87bb7

Please sign in to comment.