HHH-4917 - Keyword TYPE not supported
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18814 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
6a2843f98a
commit
6acf72f54a
|
@ -63,12 +63,34 @@ public class MethodNode extends AbstractSelectExpression implements SelectExpres
|
|||
AST exprList = name.getNextSibling();
|
||||
// If the expression list has exactly one expression, and the type of the expression is a collection
|
||||
// then this might be a collection function, such as index(c) or size(c).
|
||||
if ( ASTUtil.hasExactlyOneChild( exprList ) && isCollectionPropertyMethod() ) {
|
||||
collectionProperty( exprList.getFirstChild(), name );
|
||||
if ( ASTUtil.hasExactlyOneChild( exprList ) ) {
|
||||
if ( "type".equals( methodName ) ) {
|
||||
typeDiscriminator( exprList.getFirstChild() );
|
||||
return;
|
||||
}
|
||||
if ( isCollectionPropertyMethod() ) {
|
||||
collectionProperty( exprList.getFirstChild(), name );
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dialectFunction( exprList );
|
||||
|
||||
dialectFunction( exprList );
|
||||
}
|
||||
|
||||
private void typeDiscriminator(AST path) throws SemanticException {
|
||||
if ( path == null ) {
|
||||
throw new SemanticException( "type() discriminator reference has no path!" );
|
||||
}
|
||||
|
||||
FromReferenceNode pathAsFromReferenceNode = (FromReferenceNode) path;
|
||||
FromElement typeFromElement = pathAsFromReferenceNode.getFromElement();
|
||||
Type type = typeFromElement.getPropertyType( "class", "class" );
|
||||
setDataType( type );
|
||||
|
||||
String[] columns = typeFromElement.toColumns( typeFromElement.getTableAlias(), "class", inSelect );
|
||||
setText( columns[0] );
|
||||
|
||||
setType( SqlTokenTypes.SQL_TOKEN );
|
||||
}
|
||||
|
||||
public SQLFunction getSQLFunction() {
|
||||
|
|
|
@ -106,6 +106,20 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
|
|||
return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
|
||||
}
|
||||
|
||||
public void testJpaTypeOperator() {
|
||||
// just checking syntax here...
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
// control
|
||||
s.createQuery( "from Animal a where a.class = Dog" ).list();
|
||||
|
||||
s.createQuery( "from Animal a where type(a) = Dog" ).list();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testComponentJoins() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
|
Loading…
Reference in New Issue