|
36 | 36 | public abstract class AbstractHibernateCriterionAdapter { |
37 | 37 | protected static final Map<Class<?>, CriterionAdaptor<?>> criterionAdaptors = new HashMap<Class<?>, CriterionAdaptor<?>>(); |
38 | 38 | protected static boolean initialized; |
| 39 | + protected static final String ALIAS = "_alias"; |
39 | 40 |
|
40 | 41 | public AbstractHibernateCriterionAdapter() { |
41 | 42 | initialize(); |
@@ -154,7 +155,12 @@ public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Que |
154 | 155 | criterionAdaptors.put(Query.Exists.class, new CriterionAdaptor<Query.Exists>() { |
155 | 156 | @Override |
156 | 157 | public Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Exists criterion, String alias) { |
157 | | - DetachedCriteria detachedCriteria = toHibernateDetachedCriteria(hibernateQuery,criterion.getSubquery()); |
| 158 | + final QueryableCriteria subquery = criterion.getSubquery(); |
| 159 | + String subqueryAlias = subquery.getAlias(); |
| 160 | + if (subquery.getAlias() == null) { |
| 161 | + subqueryAlias = criterion.getSubquery().getPersistentEntity().getJavaClass().getSimpleName() + ALIAS; |
| 162 | + } |
| 163 | + DetachedCriteria detachedCriteria = toHibernateDetachedCriteria(hibernateQuery,subquery, subqueryAlias); |
158 | 164 | return Subqueries.exists(detachedCriteria); |
159 | 165 | } |
160 | 166 | }); |
@@ -537,6 +543,10 @@ public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQ |
537 | 543 |
|
538 | 544 | protected abstract org.hibernate.criterion.DetachedCriteria toHibernateDetachedCriteria(AbstractHibernateQuery query, QueryableCriteria<?> queryableCriteria); |
539 | 545 |
|
| 546 | + protected org.hibernate.criterion.DetachedCriteria toHibernateDetachedCriteria(AbstractHibernateQuery query, QueryableCriteria<?> queryableCriteria, String alias) { |
| 547 | + return toHibernateDetachedCriteria(query, queryableCriteria); |
| 548 | + } |
| 549 | + |
540 | 550 | public static abstract class CriterionAdaptor<T extends Query.Criterion> { |
541 | 551 | public abstract org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, T criterion, String alias); |
542 | 552 |
|
|
0 commit comments