Skip to content

Commit 1d87bb7

Browse files
committed
fix missing import and fix missing table name
1 parent 1b7a6d1 commit 1d87bb7

File tree

1 file changed

+15
-2
lines changed
  • cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils

1 file changed

+15
-2
lines changed

cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
import java.lang.annotation.Annotation;
44
import java.lang.reflect.Field;
55
import java.lang.reflect.Method;
6+
import java.lang.reflect.ParameterizedType;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
69
import java.util.Collection;
10+
import java.util.List;
711
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;
817

918
import org.apache.commons.lang3.ClassUtils;
19+
import org.apache.commons.lang3.StringUtils;
1020
import org.slf4j.Logger;
1121
import org.slf4j.LoggerFactory;
1222

@@ -496,13 +506,16 @@ public String getFirstEnumValue(String className) {
496506
*
497507
* @param className
498508
* 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
500510
*/
501511
public String getEntityTableName(String className) {
502512
try {
503513
Class<?> entityClass = Class.forName(className);
504514
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();
506519
} catch (ClassNotFoundException e) {
507520
LOG.error("{}: Could not find {}", e.getMessage(), className);
508521
return null;

0 commit comments

Comments
 (0)