Hi,
Although I've gotten feedback that this won't necessarily be included
as-is, or against current versions etc., since I have to update it as I
track newer Hibernate core versions (we use this modification
internally), I figure it might be of use or interest to the dev.
community.
This is the updated patch, against 3.3.1GA
Changes from last time include:
* rediffed against 3.3.1
* change to slf4j for logging
* fix the crude hack in CriteriaJoinWalker to what seems to be the
correct implementation. The issue here is complicated and not-at-all
understood by me completely.
The method in question, generateTableAlias, seems to do (at least) two
things in the CriteriaJoinWalker, one of which is to update the internal
'userAlias' list based on whether the Joinable 'consumesEntityAlias'.
This behavior needed to remain completely unmodified, which my previous
patch did not do. However, the reason I needed to modify this is that
some Joinables which DO NOT 'conumeEntityAlias' still need to provide an
SQL alias for the table.
Deciding which ones, exactly, need to do this was complicated, and I'm
not sure this is currently correct.
However, it now passes the test suite, which it didn't before.
Thanks,
David
diff --exclude='*~' --exclude='*.orig' -ru hibernate-distribution-3.3.1.GA.orig/project/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
--- hibernate-distribution-3.3.1.GA.orig/project/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2008-09-10 14:19:59.0 -0400
+++ hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2009-01-16 15:40:27.0 -0500
@@ -235,7 +235,7 @@
* @param role The collection role for whcih to retrieve the property mapping.
* @return The property mapping.
*/
- private PropertyMapping getCollectionPropertyMapping(String role) {
+public PropertyMapping getCollectionPropertyMapping(String role) {
return ( PropertyMapping ) collectionPropertyMappingByRole.get( role );
}
Only in hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/loader/criteria: ComponentCollectionCriteriaInfoProvider.java
Only in hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/loader/criteria: CriteriaInfoProvider.java
diff --exclude='*~' --exclude='*.orig' -ru hibernate-distribution-3.3.1.GA.orig/project/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java
--- hibernate-distribution-3.3.1.GA.orig/project/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2008-09-10 14:19:59.0 -0400
+++ hibernate-distribution-3.3.1.GA/project/core/src/main/java/org/hibernate/loader/criteria/CriteriaJoinWalker.java 2009-01-20 10:04:51.0 -0500
@@ -40,11 +40,15 @@
import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.AssociationType;
import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory;
import org.hibernate.util.ArrayHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A JoinWalker for Criteria queries.
*
@@ -52,6 +56,7 @@
* @author Gavin King
*/
public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
+private static final Logger logger = LoggerFactory.getLogger(CriteriaJoinWalker.class);
//TODO: add a CriteriaImplementor interface
// this class depends directly upon CriteriaImpl in the impl package...
@@ -175,19 +180,48 @@
( (Queryable) getPersister() ).filterFragment( getAlias(), getEnabledFilters() );
}
- protected String generateTableAlias(int n, String path, Joinable joinable) {
- if ( joinable.consumesEntityAlias() ) {
- final Criteria subcriteria = translator.getCriteria(path);
- String sqlAlias = subcriteria==null ? null : translator.getSQLAlias(subcriteria);
- if (sqlAlias!=null) {
-userAliasList.add( subcriteria.getAlias() ); //alias may be null
-return sqlAlias; //EARLY EXIT
+ protected String generateTableAlias(int n, String path, Joinable joinable) {
+ logger.debug("generateTableAlias n="+n+" path="+path+" joinable="+joinable);
+
+ // it's complicated as to when to return the sqlAlias designated by the 'path'.
+ // the issue is that for a collection-of-entity, the walker navigates the same
+ // path twice, once for the collection, once for the entity. the Joinable will
+ // be different for each, and the collection Joinable (probably a BasicCollectionPersister)
+ // will _NOT_ consume the alias, and also should _NOT_ assign an SQL alias.
+ // the second