diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java index 15f5e717b6..d84de171f7 100644 --- a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java +++ b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -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; @@ -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;