@@ -58,7 +58,8 @@ private JpqlQueryBuilder() {}
58
58
* @return
59
59
*/
60
60
public static Entity entity (Class <?> from ) {
61
- return new Entity (from .getName (), from .getSimpleName (),
61
+ DefaultJpaEntityMetadata <?> entityMetadata = new DefaultJpaEntityMetadata <>(from );
62
+ return new Entity (from .getName (), entityMetadata .getEntityNameOr (Class ::getName ),
62
63
getAlias (from .getSimpleName (), Predicates .isTrue (), () -> "r" ));
63
64
}
64
65
@@ -538,7 +539,8 @@ static PathAndOrigin path(Origin origin, String path) {
538
539
if (origin instanceof Entity entity ) {
539
540
540
541
try {
541
- PropertyPath from = PropertyPath .from (path , ClassUtils .forName (entity .entity , Entity .class .getClassLoader ()));
542
+ PropertyPath from = PropertyPath .from (path ,
543
+ ClassUtils .forName (entity .className , Entity .class .getClassLoader ()));
542
544
return new PathAndOrigin (from , entity , false );
543
545
} catch (ClassNotFoundException e ) {
544
546
throw new RuntimeException (e );
@@ -847,7 +849,7 @@ String render() {
847
849
StringBuilder where = new StringBuilder ();
848
850
StringBuilder orderby = new StringBuilder ();
849
851
StringBuilder result = new StringBuilder (
850
- "SELECT %s FROM %s %s" .formatted (selection .render (renderContext ), entity .getEntity (), entity .getAlias ()));
852
+ "SELECT %s FROM %s %s" .formatted (selection .render (renderContext ), entity .getName (), entity .getAlias ()));
851
853
852
854
if (getWhere () != null ) {
853
855
where .append (" WHERE " ).append (getWhere ().render (renderContext ));
@@ -1024,28 +1026,24 @@ public interface Origin {
1024
1026
*/
1025
1027
public static final class Entity implements Origin {
1026
1028
1029
+ private final String className ;
1027
1030
private final String entity ;
1028
- private final String simpleName ;
1029
1031
private final String alias ;
1030
1032
1031
1033
/**
1032
- * @param entity fully-qualified entity name.
1033
- * @param simpleName simple class name.
1034
+ * @param className fully-qualified entity name.
1035
+ * @param entity entity name (as in {@code @Entity(…)}) .
1034
1036
* @param alias alias to use.
1035
1037
*/
1036
- Entity (String entity , String simpleName , String alias ) {
1038
+ Entity (String className , String entity , String alias ) {
1039
+ this .className = className ;
1037
1040
this .entity = entity ;
1038
- this .simpleName = simpleName ;
1039
1041
this .alias = alias ;
1040
1042
}
1041
1043
1042
- public String getEntity () {
1043
- return entity ;
1044
- }
1045
-
1046
1044
@ Override
1047
1045
public String getName () {
1048
- return simpleName ;
1046
+ return entity ;
1049
1047
}
1050
1048
1051
1049
public String getAlias () {
@@ -1061,18 +1059,18 @@ public boolean equals(Object obj) {
1061
1059
return false ;
1062
1060
}
1063
1061
var that = (Entity ) obj ;
1064
- return Objects .equals (this .entity , that .entity ) && Objects .equals (this .simpleName , that .simpleName )
1062
+ return Objects .equals (this .entity , that .entity ) && Objects .equals (this .className , that .className )
1065
1063
&& Objects .equals (this .alias , that .alias );
1066
1064
}
1067
1065
1068
1066
@ Override
1069
1067
public int hashCode () {
1070
- return Objects .hash (entity , simpleName , alias );
1068
+ return Objects .hash (entity , className , alias );
1071
1069
}
1072
1070
1073
1071
@ Override
1074
1072
public String toString () {
1075
- return "Entity[" + "entity=" + entity + ", " + "simpleName =" + simpleName + ", " + "alias=" + alias + ']' ;
1073
+ return "Entity[" + "entity=" + entity + ", " + "className =" + className + ", " + "alias=" + alias + ']' ;
1076
1074
}
1077
1075
1078
1076
}
0 commit comments