@@ -58,7 +58,8 @@ private JpqlQueryBuilder() {}
5858 * @return
5959 */
6060 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 ),
6263 getAlias (from .getSimpleName (), Predicates .isTrue (), () -> "r" ));
6364 }
6465
@@ -538,7 +539,8 @@ static PathAndOrigin path(Origin origin, String path) {
538539 if (origin instanceof Entity entity ) {
539540
540541 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 ()));
542544 return new PathAndOrigin (from , entity , false );
543545 } catch (ClassNotFoundException e ) {
544546 throw new RuntimeException (e );
@@ -847,7 +849,7 @@ String render() {
847849 StringBuilder where = new StringBuilder ();
848850 StringBuilder orderby = new StringBuilder ();
849851 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 ()));
851853
852854 if (getWhere () != null ) {
853855 where .append (" WHERE " ).append (getWhere ().render (renderContext ));
@@ -1024,28 +1026,24 @@ public interface Origin {
10241026 */
10251027 public static final class Entity implements Origin {
10261028
1029+ private final String className ;
10271030 private final String entity ;
1028- private final String simpleName ;
10291031 private final String alias ;
10301032
10311033 /**
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(…)}) .
10341036 * @param alias alias to use.
10351037 */
1036- Entity (String entity , String simpleName , String alias ) {
1038+ Entity (String className , String entity , String alias ) {
1039+ this .className = className ;
10371040 this .entity = entity ;
1038- this .simpleName = simpleName ;
10391041 this .alias = alias ;
10401042 }
10411043
1042- public String getEntity () {
1043- return entity ;
1044- }
1045-
10461044 @ Override
10471045 public String getName () {
1048- return simpleName ;
1046+ return entity ;
10491047 }
10501048
10511049 public String getAlias () {
@@ -1061,18 +1059,18 @@ public boolean equals(Object obj) {
10611059 return false ;
10621060 }
10631061 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 )
10651063 && Objects .equals (this .alias , that .alias );
10661064 }
10671065
10681066 @ Override
10691067 public int hashCode () {
1070- return Objects .hash (entity , simpleName , alias );
1068+ return Objects .hash (entity , className , alias );
10711069 }
10721070
10731071 @ Override
10741072 public String toString () {
1075- return "Entity[" + "entity=" + entity + ", " + "simpleName =" + simpleName + ", " + "alias=" + alias + ']' ;
1073+ return "Entity[" + "entity=" + entity + ", " + "className =" + className + ", " + "alias=" + alias + ']' ;
10761074 }
10771075
10781076 }
0 commit comments