From a514460bb9b686d1e4e9aad86acd5eb86ca15bcb Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Fri, 5 Mar 2021 12:28:45 +0100 Subject: [PATCH 1/2] HHH-9182 Cleanup grammar ambiguity issues --- hibernate-core/src/main/antlr/hql.g | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/antlr/hql.g b/hibernate-core/src/main/antlr/hql.g index bd05e70aea..3f27822631 100644 --- a/hibernate-core/src/main/antlr/hql.g +++ b/hibernate-core/src/main/antlr/hql.g @@ -596,8 +596,8 @@ equalityExpression // token type. When traversing the AST, use the token type, and not the // token text to interpret the semantics of these nodes. relationalExpression - : concatenation ( - ( ( ( LT^ | GT^ | LE^ | GE^ ) additiveExpression )* ) + : ( concatenation | quantifiedExpression ) ( + ( ( ( LT^ | GT^ | LE^ | GE^ ) ( additiveExpression | quantifiedExpression ) )* ) // Disable node production for the optional 'not'. | (n:NOT!)? ( // Represent the optional NOT prefix using the token type by @@ -668,7 +668,6 @@ unaryExpression : MINUS^ {#MINUS.setType(UNARY_MINUS);} unaryExpression | PLUS^ {#PLUS.setType(UNARY_PLUS);} unaryExpression | caseExpression - | quantifiedExpression | atom ; @@ -842,9 +841,9 @@ castedIdentPrimaryBase ; aggregate - : ( SUM^ | AVG^ | MAX^ | MIN^ ) OPEN! ( concatenation | subQuery ) CLOSE! { #aggregate.setType(AGGREGATE); } + : ( SUM^ | AVG^ | MAX^ | MIN^ ) OPEN! ( concatenation ) CLOSE! { #aggregate.setType(AGGREGATE); } // Special case for count - It's 'parameters' can be keywords. - | COUNT^ OPEN! ( STAR { #STAR.setType(ROW_STAR); } | ( ( DISTINCT | ALL )? ( concatenation | subQuery ) ) ) CLOSE! + | COUNT^ OPEN! ( STAR { #STAR.setType(ROW_STAR); } | ( ( DISTINCT | ALL )? ( concatenation ) ) ) CLOSE! | collectionExpr ; From 9952c0984354a45e293213ae3257071dd5eca3fd Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 10 Mar 2021 16:23:42 -0600 Subject: [PATCH 2/2] HHH-14491 - Apply default allocation/increment size for @GeneratedValue(AUTO) HHH-14492 - Prefer sequence-per-entity (hierarchy) for @GeneratedValue(AUTO) by default - added test as @FailureExpected to track this into 6.0 --- .../enhanced/auto/NewGeneratorsTests.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/auto/NewGeneratorsTests.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/auto/NewGeneratorsTests.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/auto/NewGeneratorsTests.java new file mode 100644 index 0000000000..5d73e16074 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/auto/NewGeneratorsTests.java @@ -0,0 +1,88 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.idgen.enhanced.auto; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.id.enhanced.DatabaseStructure; +import org.hibernate.id.enhanced.SequenceStyleGenerator; +import org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.tool.schema.Action; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Steve Ebersole + */ +public class NewGeneratorsTests extends BaseUnitTestCase { + @Test + @FailureExpected( + jiraKey = "HHH-14491", + message = "To be implemented for 6; see https://github.com/hibernate/hibernate-orm/discussions/3809" + ) + public void testAutoDefaults() { + // check that `@GeneratedValue(AUTO)` with no explicit generator applies + // various defaults: + // - allocation/increment size = 50 + // - sequence-per-entity with a suffix + + final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(); + ssrb.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ); + + final StandardServiceRegistry ssr = ssrb.build(); + final Metadata metadata = new MetadataSources( ssr ) + .addAnnotatedClass( Entity1.class ) + .buildMetadata(); + + final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory(); + generatorFactory.injectServices( (ServiceRegistryImplementor) ssr ); + + final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() ); + final SequenceStyleGenerator generator = (SequenceStyleGenerator) entityBinding.getRootClass().getIdentifier().createIdentifierGenerator( + generatorFactory, + new H2Dialect(), + "", + "", + entityBinding.getRootClass() + ); + + final DatabaseStructure databaseStructure = generator.getDatabaseStructure(); + + // HHH-14491 - what we want to happen + assertThat( databaseStructure.getName(), is( "Entity1_SEQ" ) ); + // or this depending on the discussion (Jira) about using entity name v. table name as the base + assertThat( databaseStructure.getName(), is( "tbl_1_SEQ" ) ); + + // HHH-14491 - this is what we want to have happen + assertThat( databaseStructure.getIncrementSize(), is( 50 ) ); + } + + @Entity( name = "Entity1" ) + @Table( name = "tbl_1" ) + public static class Entity1 { + @Id + @GeneratedValue( strategy = GenerationType.AUTO ) + private Integer id; + } +}