diff --git a/core/src/main/java/org/hibernate/sql/Template.java b/core/src/main/java/org/hibernate/sql/Template.java index 68cb61e7ea..057c0ea2e4 100644 --- a/core/src/main/java/org/hibernate/sql/Template.java +++ b/core/src/main/java/org/hibernate/sql/Template.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.StringTokenizer; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.util.StringHelper; import org.hibernate.sql.ordering.antlr.ColumnMapper; @@ -317,11 +318,29 @@ public final class Template { private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) { return "(".equals(nextToken) || KEYWORDS.contains(lcToken) || - functionRegistry.hasFunction(lcToken) || + isFunction(lcToken, nextToken, functionRegistry ) || dialect.getKeywords().contains(lcToken) || FUNCTION_KEYWORDS.contains(lcToken); } + private static boolean isFunction(String lcToken, String nextToken, SQLFunctionRegistry functionRegistry) { + // checking for "(" is currently redundant because it is checked before getting here; + // doing the check anyhow, in case that earlier check goes away; + if ( "(".equals( nextToken ) ) { + return true; + } + SQLFunction function = functionRegistry.findSQLFunction(lcToken); + if ( function == null ) { + // lcToken does not refer to a function + return false; + } + // if function.hasArguments() and function.hasParenthesesIfNoArguments() is true, + // then assume that lcToken is not a function, since it is not followed by "("; + // can't seem to use function.hasParenthesesIfNoArguments() alone because + // function definitions may return true if "()" is optional when there are no arguments. + return function.hasArguments() && function.hasParenthesesIfNoArguments() ? false : true; + } + private static boolean isIdentifier(String token, Dialect dialect) { return token.charAt(0)=='`' || ( //allow any identifier quoted with backtick Character.isLetter( token.charAt(0) ) && //only recognizes identifiers beginning with a letter diff --git a/testsuite/src/test/java/org/hibernate/test/hql/EntityWithArgFunctionAsColumn.java b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithArgFunctionAsColumn.java new file mode 100644 index 0000000000..3920bcfdeb --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithArgFunctionAsColumn.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + * + */ +package org.hibernate.test.hql; + +/** + * + * @author Gail Badner + */ +public class EntityWithArgFunctionAsColumn { + private long id; + private int lower; + private String upper; + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + + public int getLower() { + return lower; + } + public void setLower(int lower) { + this.lower = lower; + } + + public String getUpper() { + return upper; + } + public void setUpper(String upper) { + this.upper = upper; + } +} diff --git a/testsuite/src/test/java/org/hibernate/test/hql/EntityWithFunctionAsColumnHolder.java b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithFunctionAsColumnHolder.java new file mode 100644 index 0000000000..1b75648d9b --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithFunctionAsColumnHolder.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + * + */ +package org.hibernate.test.hql; + +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Gail Badner + */ +public class EntityWithFunctionAsColumnHolder { + private long id; + private EntityWithFunctionAsColumnHolder nextHolder; + private Set entityWithArgFunctionAsColumns = new HashSet(); + private Set entityWithNoArgFunctionAsColumns = new HashSet(); + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + + public EntityWithFunctionAsColumnHolder getNextHolder() { + return nextHolder; + } + public void setNextHolder(EntityWithFunctionAsColumnHolder nextHolder) { + this.nextHolder = nextHolder; + } + + public Set getEntityWithArgFunctionAsColumns() { + return entityWithArgFunctionAsColumns; + } + public void setEntityWithArgFunctionAsColumns(Set entityWithArgFunctionAsColumns) { + this.entityWithArgFunctionAsColumns = entityWithArgFunctionAsColumns; + } + + public Set getEntityWithNoArgFunctionAsColumns() { + return entityWithNoArgFunctionAsColumns; + } + public void setEntityWithNoArgFunctionAsColumns(Set entityWithNoArgFunctionAsColumns) { + this.entityWithNoArgFunctionAsColumns = entityWithNoArgFunctionAsColumns; + } +} \ No newline at end of file diff --git a/testsuite/src/test/java/org/hibernate/test/hql/EntityWithNoArgFunctionAsColumn.java b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithNoArgFunctionAsColumn.java new file mode 100644 index 0000000000..1c078f3ed4 --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/hql/EntityWithNoArgFunctionAsColumn.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + * + */ +package org.hibernate.test.hql; + +/** + * + * @author Gail Badner + */ +public class EntityWithNoArgFunctionAsColumn { + private long id; + private String user; + private String currentDate; + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + + public String getUser() { + return user; + } + public void setUser(String user) { + this.user = user; + } + + public String getCurrentDate() { + return currentDate; + } + public void setCurrentDate(String currentDate) { + this.currentDate = currentDate; + } +} diff --git a/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java b/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java new file mode 100644 index 0000000000..27555a5b23 --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/hql/FunctionNameAsColumnTest.java @@ -0,0 +1,332 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + * + */ +package org.hibernate.test.hql; + +import java.util.List; + +import junit.framework.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.hibernate.FetchMode; +import org.hibernate.Hibernate; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.criterion.Restrictions; +import org.hibernate.junit.functional.FunctionalTestCase; +import org.hibernate.junit.functional.FunctionalTestClassTestSuite; + +/** + * Tests HQL and Criteria queries using DB columns having the same name as registerd functions. + * + * @author Gail Badner + */ +public class FunctionNameAsColumnTest extends FunctionalTestCase { + + private static final Logger log = LoggerFactory.getLogger( FunctionNameAsColumnTest.class ); + + public FunctionNameAsColumnTest(String name) { + super( name ); + } + + public String[] getMappings() { + return new String[] { + "hql/FunctionNamesAsColumns.hbm.xml" + }; + } + + public void configure(Configuration cfg) { + super.configure( cfg ); + cfg.setProperty( Environment.USE_QUERY_CACHE, "false" ); + } + + public static Test suite() { + return new FunctionalTestClassTestSuite( FunctionNameAsColumnTest.class ); + } + + public void testGetOneColumnSameNameAsArgFunctionHQL() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithArgFunctionAsColumn e = new EntityWithArgFunctionAsColumn(); + e.setLower( 3 ); + e.setUpper( " abc " ); + s.persist( e ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + e = ( EntityWithArgFunctionAsColumn ) s.createQuery( "from EntityWithArgFunctionAsColumn" ).uniqueResult(); + assertEquals( 3, e.getLower() ); + assertEquals( " abc ", e.getUpper() ); + t.commit(); + s.close(); + + cleanup(); + } + + public void testGetOneColumnSameNameAsArgFunctionCriteria() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithArgFunctionAsColumn e = new EntityWithArgFunctionAsColumn(); + e.setLower( 3 ); + e.setUpper( " abc " ); + s.persist( e ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + e = ( EntityWithArgFunctionAsColumn ) s.createCriteria( EntityWithArgFunctionAsColumn.class ).uniqueResult(); + assertEquals( 3, e.getLower() ); + assertEquals( " abc ", e.getUpper() ); + t.commit(); + s.close(); + + cleanup(); + } + + public void testGetMultiColumnSameNameAsArgFunctionHQL() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithArgFunctionAsColumn e1 = new EntityWithArgFunctionAsColumn(); + e1.setLower( 3 ); + e1.setUpper( " abc " ); + EntityWithArgFunctionAsColumn e2 = new EntityWithArgFunctionAsColumn(); + e2.setLower( 999 ); + e2.setUpper( " xyz " ); + EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder(); + holder1.getEntityWithArgFunctionAsColumns().add( e1 ); + EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder(); + holder2.getEntityWithArgFunctionAsColumns().add( e2 ); + holder1.setNextHolder( holder2 ); + s.save( holder1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + holder1 = ( EntityWithFunctionAsColumnHolder ) s.createQuery( + "from EntityWithFunctionAsColumnHolder h left join fetch h.entityWithArgFunctionAsColumns " + + "left join fetch h.nextHolder left join fetch h.nextHolder.entityWithArgFunctionAsColumns " + + "where h.nextHolder is not null" ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( holder1.getEntityWithArgFunctionAsColumns() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithArgFunctionAsColumns() ) ); + assertEquals( 1, holder1.getEntityWithArgFunctionAsColumns().size() ); + e1 = ( EntityWithArgFunctionAsColumn ) holder1.getEntityWithArgFunctionAsColumns().iterator().next(); + assertEquals( 3, e1.getLower() ); + assertEquals( " abc ", e1.getUpper() ); + assertEquals( 1, holder1.getNextHolder().getEntityWithArgFunctionAsColumns().size() ); + e2 = ( EntityWithArgFunctionAsColumn ) ( holder1.getNextHolder() ).getEntityWithArgFunctionAsColumns().iterator().next(); + assertEquals( 999, e2.getLower() ); + assertEquals( " xyz ", e2.getUpper() ); + t.commit(); + s.close(); + + cleanup(); + } + + public void testGetMultiColumnSameNameAsArgFunctionCriteria() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithArgFunctionAsColumn e1 = new EntityWithArgFunctionAsColumn(); + e1.setLower( 3 ); + e1.setUpper( " abc " ); + EntityWithArgFunctionAsColumn e2 = new EntityWithArgFunctionAsColumn(); + e2.setLower( 999 ); + e2.setUpper( " xyz " ); + EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder(); + holder1.getEntityWithArgFunctionAsColumns().add( e1 ); + EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder(); + holder2.getEntityWithArgFunctionAsColumns().add( e2 ); + holder1.setNextHolder( holder2 ); + s.save( holder1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class ) + .add( Restrictions.isNotNull( "nextHolder" )) + .setFetchMode( "entityWithArgFunctionAsColumns", FetchMode.JOIN ) + .setFetchMode( "nextHolder", FetchMode.JOIN ) + .setFetchMode( "nextHolder.entityWithArgFunctionAsColumns", FetchMode.JOIN ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( holder1.getEntityWithArgFunctionAsColumns() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithArgFunctionAsColumns() ) ); + assertEquals( 1, holder1.getEntityWithArgFunctionAsColumns().size() ); + e1 = ( EntityWithArgFunctionAsColumn ) holder1.getEntityWithArgFunctionAsColumns().iterator().next(); + assertEquals( 3, e1.getLower() ); + assertEquals( " abc ", e1.getUpper() ); + assertEquals( 1, holder1.getNextHolder().getEntityWithArgFunctionAsColumns().size() ); + e2 = ( EntityWithArgFunctionAsColumn ) ( holder1.getNextHolder() ).getEntityWithArgFunctionAsColumns().iterator().next(); + assertEquals( 999, e2.getLower() ); + assertEquals( " xyz ", e2.getUpper() ); + t.commit(); + s.close(); + + cleanup(); + } + + public void testGetMultiColumnSameNameAsNoArgFunctionHQL() throws Exception { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn(); + e1.setCurrentDate( "blah blah blah" ); + EntityWithNoArgFunctionAsColumn e2 = new EntityWithNoArgFunctionAsColumn(); + e2.setCurrentDate( "yadda yadda yadda" ); + EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder(); + holder1.getEntityWithNoArgFunctionAsColumns().add( e1 ); + EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder(); + holder2.getEntityWithNoArgFunctionAsColumns().add( e2 ); + holder1.setNextHolder( holder2 ); + s.save( holder1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + holder1 = ( EntityWithFunctionAsColumnHolder ) s.createQuery( + "from EntityWithFunctionAsColumnHolder h left join fetch h.entityWithNoArgFunctionAsColumns " + + "left join fetch h.nextHolder left join fetch h.nextHolder.entityWithNoArgFunctionAsColumns " + + "where h.nextHolder is not null" ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( holder1.getEntityWithNoArgFunctionAsColumns() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns() ) ); + assertEquals( 1, holder1.getEntityWithNoArgFunctionAsColumns().size() ); + t.commit(); + s.close(); + + e1 = ( EntityWithNoArgFunctionAsColumn ) holder1.getEntityWithNoArgFunctionAsColumns().iterator().next(); + assertEquals( "blah blah blah", e1.getCurrentDate() ); + assertEquals( 1, holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns().size() ); + e2 = ( EntityWithNoArgFunctionAsColumn ) ( holder1.getNextHolder() ).getEntityWithNoArgFunctionAsColumns().iterator().next(); + assertEquals( "yadda yadda yadda", e2.getCurrentDate() ); + + cleanup(); + } + + public void testGetMultiColumnSameNameAsNoArgFunctionCriteria() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn(); + e1.setCurrentDate( "blah blah blah" ); + EntityWithNoArgFunctionAsColumn e2 = new EntityWithNoArgFunctionAsColumn(); + e2.setCurrentDate( "yadda yadda yadda" ); + EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder(); + holder1.getEntityWithNoArgFunctionAsColumns().add( e1 ); + EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder(); + holder2.getEntityWithNoArgFunctionAsColumns().add( e2 ); + holder1.setNextHolder( holder2 ); + s.save( holder1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + holder1 = ( EntityWithFunctionAsColumnHolder ) s.createCriteria( EntityWithFunctionAsColumnHolder.class ) + .add( Restrictions.isNotNull( "nextHolder" )) + .setFetchMode( "entityWithNoArgFunctionAsColumns", FetchMode.JOIN ) + .setFetchMode( "nextHolder", FetchMode.JOIN ) + .setFetchMode( "nextHolder.entityWithNoArgFunctionAsColumns", FetchMode.JOIN ) + .uniqueResult(); + assertTrue( Hibernate.isInitialized( holder1.getEntityWithNoArgFunctionAsColumns() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder() ) ); + assertTrue( Hibernate.isInitialized( holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns() ) ); + assertEquals( 1, holder1.getEntityWithNoArgFunctionAsColumns().size() ); + e1 = ( EntityWithNoArgFunctionAsColumn ) holder1.getEntityWithNoArgFunctionAsColumns().iterator().next(); + assertEquals( "blah blah blah", e1.getCurrentDate() ); + assertEquals( 1, holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns().size() ); + e2 = ( EntityWithNoArgFunctionAsColumn ) ( holder1.getNextHolder() ).getEntityWithNoArgFunctionAsColumns().iterator().next(); + assertEquals( "yadda yadda yadda", e2.getCurrentDate() ); + t.commit(); + s.close(); + + cleanup(); + } + + public void testNoArgFcnAndColumnSameNameAsNoArgFunctionHQL() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn(); + e1.setCurrentDate( "blah blah blah" ); + EntityWithNoArgFunctionAsColumn e2 = new EntityWithNoArgFunctionAsColumn(); + e2.setCurrentDate( "yadda yadda yadda" ); + EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder(); + holder1.getEntityWithNoArgFunctionAsColumns().add( e1 ); + EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder(); + holder2.getEntityWithNoArgFunctionAsColumns().add( e2 ); + holder1.setNextHolder( holder2 ); + s.save( holder1 ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + List results = s.createQuery( + "select str(current_date), currentDate from EntityWithNoArgFunctionAsColumn" + ).list(); + assertEquals( 2, results.size() ); + assertEquals( ( ( Object[] ) results.get( 0 ) )[ 0 ], ( ( Object[] ) results.get( 1 ) )[ 0 ] ); + assertTrue( ! ( ( Object[] ) results.get( 0 ) )[ 0 ].equals( ( ( Object[] ) results.get( 0 ) )[ 1 ] ) ); + assertTrue( ! ( ( Object[] ) results.get( 1 ) )[ 0 ].equals( ( ( Object[] ) results.get( 1 ) )[ 1 ] ) ); + assertTrue( ( ( Object[] ) results.get( 0 ) )[ 1 ].equals( e1.getCurrentDate() ) || + ( ( Object[] ) results.get( 0 ) )[ 1 ].equals( e2.getCurrentDate() ) ); + assertTrue( ( ( Object[] ) results.get( 1 ) )[ 1 ].equals( e1.getCurrentDate() ) || + ( ( Object[] ) results.get( 1 ) )[ 1 ].equals( e2.getCurrentDate() ) ); + assertFalse( ( ( Object[] ) results.get( 0 ) )[ 1 ].equals( ( ( Object[] ) results.get( 1 ) )[ 1 ] ) ); + t.commit(); + s.close(); + + cleanup(); + } + + private void cleanup() { + Session s = openSession(); + Transaction t = s.beginTransaction(); + s.createQuery( "delete from EntityWithArgFunctionAsColumn" ).executeUpdate(); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.createQuery( "delete from EntityWithNoArgFunctionAsColumn" ).executeUpdate(); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.createQuery( "delete from EntityWithFunctionAsColumnHolder where nextHolder is not null" ).executeUpdate(); + s.createQuery( "delete from EntityWithFunctionAsColumnHolder" ).executeUpdate(); + t.commit(); + s.close(); + } +} diff --git a/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml b/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml new file mode 100644 index 0000000000..d02a25b58a --- /dev/null +++ b/testsuite/src/test/java/org/hibernate/test/hql/FunctionNamesAsColumns.hbm.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file