diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/Concrete.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/Concrete.java new file mode 100644 index 0000000000..049a4c5f92 --- /dev/null +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/Concrete.java @@ -0,0 +1,7 @@ +package org.hibernate.processor.test.data.basic; + +import jakarta.data.repository.Repository; + +@Repository +public interface Concrete extends IdOperations { +} diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/DataTest.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/DataTest.java index 8234aa4b11..7fcf07a4c8 100644 --- a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/DataTest.java +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/DataTest.java @@ -11,6 +11,7 @@ import org.hibernate.processor.test.util.WithClasses; import org.junit.Test; import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; +import static org.hibernate.processor.test.util.TestUtil.assertNoMetamodelClassGeneratedFor; import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; /** @@ -18,7 +19,7 @@ import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsStr */ public class DataTest extends CompilationTest { @Test - @WithClasses({ Author.class, Book.class, BookAuthorRepository.class }) + @WithClasses({ Author.class, Book.class, BookAuthorRepository.class, IdOperations.class, Concrete.class }) public void test() { System.out.println( getMetaModelSourceAsString( Author.class ) ); System.out.println( getMetaModelSourceAsString( Book.class ) ); @@ -30,5 +31,7 @@ public class DataTest extends CompilationTest { assertMetamodelClassGeneratedFor( Author.class ); assertMetamodelClassGeneratedFor( Book.class ); assertMetamodelClassGeneratedFor( BookAuthorRepository.class ); + assertMetamodelClassGeneratedFor( Concrete.class ); + assertNoMetamodelClassGeneratedFor( IdOperations.class ); } } diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/IdOperations.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/IdOperations.java new file mode 100644 index 0000000000..0f45d49beb --- /dev/null +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/IdOperations.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2023,2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package org.hibernate.processor.test.data.basic; + +import java.util.List; +import java.util.stream.Stream; + +import jakarta.data.Limit; +import jakarta.data.Order; +import jakarta.data.Sort; +import jakarta.data.repository.Query; + +/** + * This interface contains common operations for the NaturalNumbers and AsciiCharacters repositories. + * + * @param type of entity. + */ +public interface IdOperations { + @Query("where id(this) between ?1 and ?2") + Stream findByIdBetween(long minimum, long maximum, Sort sort); + + @Query("where id(this) >= ?1") + List findByIdGreaterThanEqual(long minimum, + Limit limit, + Order sorts); + + @Query("where id(this) > ?1") + T[] findByIdLessThan(long exclusiveMax, Sort primarySort, Sort secondarySort); + + @Query("where id(this) <= ?1") + List findByIdLessThanEqual(long maximum, Order sorts); +} \ No newline at end of file diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java index ed066a8641..1238e453a7 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java @@ -2177,14 +2177,17 @@ public class AnnotationMetaEntity extends AnnotationMeta { String thisText = ""; final List allTokens = hqlLexer.getAllTokens(); for (Token token : allTokens) { - switch ( token.getType() ) { + if ( token.getType() == IDENTIFIER ) { //TEMPORARY until HQL gets support for 'this' - case IDENTIFIER: - final String text = token.getText(); - if ( text.equalsIgnoreCase("this") ) { - thisText = " as " + text; - } - break; + final String text = token.getText(); + if ( text.equalsIgnoreCase("this") ) { + thisText = " as " + text; + } + break; + } + } + for (Token token : allTokens) { + switch ( token.getType() ) { case FROM: return hql; case WHERE: @@ -2238,7 +2241,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { hql, returnType, true, - new ErrorHandler( context, method, mirror, value, hql), + new ErrorHandler( context, isLocal(method) ? method : element, mirror, value, hql ), ProcessorSessionFactory.create( context.getProcessingEnvironment() ) ); if ( statement != null ) {