diff --git a/core/src/main/java/org/hibernate/dialect/Dialect.java b/core/src/main/java/org/hibernate/dialect/Dialect.java index 5247deda38..70e61c49f7 100644 --- a/core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/core/src/main/java/org/hibernate/dialect/Dialect.java @@ -1578,6 +1578,19 @@ public abstract class Dialect { return ""; } + /** + * Get the separator to use for definining cross joins when translating HQL queries. + *
+ * Typically this will be either [ cross join ] or [, ] + * + * Note that the spaces are important! + * + * @return + */ + public String getCrossJoinSeparator() { + return " cross join "; + } + // Informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java index e8cb31d79b..9f7fb24d7c 100644 --- a/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java +++ b/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java @@ -210,6 +210,13 @@ public class Oracle8iDialect extends Dialect { return new OracleJoinFragment(); } + /** + * {@inheritDoc} + */ + public String getCrossJoinSeparator() { + return ", "; + } + /** * Map case support to the Oracle DECODE function. Oracle did not * add support for CASE until 9i. diff --git a/core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java b/core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java index db89359738..b8b1351457 100644 --- a/core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java +++ b/core/src/main/java/org/hibernate/dialect/Sybase11Dialect.java @@ -40,4 +40,7 @@ public class Sybase11Dialect extends AbstractTransactSQLDialect { return new Sybase11JoinFragment(); } + public String getCrossJoinSeparator() { + return ", "; + } } diff --git a/core/src/main/java/org/hibernate/dialect/TimesTenDialect.java b/core/src/main/java/org/hibernate/dialect/TimesTenDialect.java index 4fa72faaeb..2a3bc82dbb 100644 --- a/core/src/main/java/org/hibernate/dialect/TimesTenDialect.java +++ b/core/src/main/java/org/hibernate/dialect/TimesTenDialect.java @@ -139,6 +139,10 @@ public class TimesTenDialect extends Dialect { return new OracleJoinFragment(); } + public String getCrossJoinSeparator() { + return ", "; + } + // new methods in dialect3 /*public boolean supportsForUpdateNowait() { return false; diff --git a/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java b/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java index 22174d08cd..f6433e40d8 100644 --- a/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java +++ b/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java @@ -58,6 +58,8 @@ import org.slf4j.LoggerFactory; public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter { private static final Logger log = LoggerFactory.getLogger( SqlGenerator.class ); + public static boolean REGRESSION_STYLE_CROSS_JOINS = false; + /** * all append invocations on the buf should go through this Output instance variable. * The value of this variable may be temporarily substitued by sql function processing code @@ -301,7 +303,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter { // right represents a joins originating from left; or // both right and left reprersent joins originating from the same FromElement if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) { - out( ", " ); + writeCrossJoinSeparator(); } else { out( " " ); @@ -309,8 +311,17 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter { } else { // these are just two unrelated table references + writeCrossJoinSeparator(); + } + } + + private void writeCrossJoinSeparator() { + if ( REGRESSION_STYLE_CROSS_JOINS ) { out( ", " ); } + else { + out( sessionFactory.getDialect().getCrossJoinSeparator() ); + } } protected void nestedFromFragment(AST d, AST parent) { diff --git a/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java b/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java index 33c3dbaaf9..9b8603c600 100644 --- a/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java +++ b/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java @@ -34,6 +34,7 @@ import org.hibernate.hql.ast.ASTQueryTranslatorFactory; import org.hibernate.hql.ast.DetailedSemanticException; import org.hibernate.hql.ast.QuerySyntaxException; import org.hibernate.hql.ast.QueryTranslatorImpl; +import org.hibernate.hql.ast.SqlGenerator; import org.hibernate.hql.ast.tree.ConstructorNode; import org.hibernate.hql.ast.tree.DotNode; import org.hibernate.hql.ast.tree.FromReferenceNode; @@ -73,12 +74,14 @@ public class HQLTest extends QueryTranslatorTestCase { throw new QueryException( "illegal syntax near collection: " + propertyName ); } }; + SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = true; } protected void cleanupTest() throws Exception { SelectClause.VERSION2_SQL = false; DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = false; DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = DotNode.DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER; + SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = false; super.cleanupTest(); }