okay, so i got around this issue... this is a hack, but it works.. i only did this b/c i saw the that y0_ behavior was intentional ( Gavin has commented about how it is valid SQL and should be acceptable -- not sure of the msg id, but it's somewhere in this forum ). as such, i figured a hack was the only way around it.
basically what i do is define aliases for all of my projected parameters. from the previous posts, i assume you did something like this to generate the query:
Code:
List projectedTuples =
session.createCriteria(Foo.class)
.add( ... your where clauses ... )
.setProjection(Projections.distinct(
Projections.property("juridesk_navn") // or whatever
)
)
.list();
Since you're projecting a column AND using it in the WHERE clause, this error occurs.
What I did was add a prefix to each column name and set that as the alias , then I use a result transformer to return the alias as it should be:
Code:
String prefix = "alias_";
List projectedTuples =
session.createCriteria(Foo.class)
.add( ... your where clauses ... )
.setProjection(Projections.distinct(
Projections.property("juridesk_navn",prefix + "juridesk_navn") // or whatever
)
)
.setResultTransformer(new PrefixedAliastoBeanResultTransformer())
.list();
for some reason, this tricks hibernate into NOT using the y0_ in the where clause... now i just mod'd the AliasToBeanResultTransformer's transformTuple method to trim off the alias:
Code:
public static final String ALIAS_PREFIX = "alias_";
public Object transformTuple(Object[] tuple, String[] aliases)
{
Object result;
try
{
if (setters == null)
{
setters = new Setter[ aliases.length ];
for (int i = 0; i < aliases.length; i++)
{
String alias = aliases[ i ];
if (alias != null)
{
if (alias.startsWith(ALIAS_PREFIX))
{
alias = alias.substring(ALIAS_PREFIX.length());
if (mLogger.isDebugEnabled())
{
mLogger.debug("transformTuple: getting property: " + alias);
}
}
setters[ i ] = propertyAccessor.getSetter(resultClass, alias);
}
}
}
result = resultClass.newInstance();
for (int i = 0; i < aliases.length; i++)
{
if (setters[ i ] != null)
{
setters[ i ].set(result, tuple[ i ], null);
}
}
}
catch (InstantiationException e)
{
throw new HibernateException("Could not instantiate resultclass: " +
resultClass.getName());
}
catch (IllegalAccessException e)
{
throw new HibernateException("Could not instantiate resultclass: " +
resultClass.getName());
}
return result;
}
then i also created a static buildProjection method in this class that creates the projected columns w/ aliases:
Code:
/**
* Builds a projection for a list of properties.
* @param properties The list of properties to project.
* @return A projection.
*/
public Projection buildProjection(String[] properties)
{
ProjectionList list = Projections.projectionList();
int count = properties.length;
for (int i = 0; i < count; ++i)
{
list.add(Projections.property(properties[ i ]),
ALIAS_PREFIX + properties[ i ]);
}
return list;
}
[/code]
i don't really like this, but it works.
good luck!