Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSEARCH-5226 Ignore collecting scale on formula properties (6.2) #4287

Draft
wants to merge 1 commit into
base: 6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions orm6/integrationtest/mapper/orm/ant-src-changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,149 @@ index decda9e0ef..f99343ff26 100644
.contains( "_containing_fk_containingidBackref" )
.contains( "_containingIndexBackref" );

diff --git a/test/java/org/hibernate/search/integrationtest/mapper/orm/model/FormulaPropertyIT.java b/test/java/org/hibernate/search/integrationtest/mapper/orm/model/FormulaPropertyIT.java
new file mode 100644
index 0000000000..cd7f26ead1
--- /dev/null
+++ b/test/java/org/hibernate/search/integrationtest/mapper/orm/model/FormulaPropertyIT.java
@@ -0,0 +1,137 @@
+/*
+ * Hibernate Search, full-text search for your domain model
+ *
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
+ */
+package org.hibernate.search.integrationtest.mapper.orm.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.OneToMany;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.annotations.Formula;
+import org.hibernate.search.engine.backend.analysis.AnalyzerNames;
+import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate;
+import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
+import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
+import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
+import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency;
+import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
+import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class FormulaPropertyIT {
+
+ @Rule
+ public BackendMock backendMock = new BackendMock();
+
+ @Rule
+ public OrmSetupHelper ormSetupHelper = OrmSetupHelper.withBackendMock( backendMock );
+
+ private SessionFactory sessionFactory;
+
+ @Before
+ public void setup() {
+ backendMock.expectSchema( IndexedEntity.INDEX, b -> b
+ .field( "string", String.class, b2 -> b2.analyzerName( AnalyzerNames.DEFAULT ) )
+ ).expectSchema( RootEntity.INDEX, b -> b
+ .objectField( "entityShallow",
+ b1 -> b1.field( "string", String.class, b2 -> b2.analyzerName( AnalyzerNames.DEFAULT ) ) )
+ .objectField( "entityMapped",
+ b1 -> b1.field( "string", String.class, b2 -> b2.analyzerName( AnalyzerNames.DEFAULT ) ) ) );
+
+ sessionFactory = ormSetupHelper.start()
+ .setup( IndexedEntity.class, RootEntity.class );
+ backendMock.verifyExpectationsMet();
+ }
+
+ @Test
+ public void index() {
+ with( sessionFactory ).runInTransaction( session -> {
+ IndexedEntity entity1 = new IndexedEntity();
+ entity1.id = 1;
+ entity1.string = "smth";
+ entity1.amount1 = 10;
+ entity1.amount2 = 20;
+
+ RootEntity rootEntity = new RootEntity();
+ rootEntity.id = 1;
+ rootEntity.entityShallow = entity1;
+ rootEntity.entityMapped = entity1;
+ entity1.rootEntities.add( rootEntity );
+
+ session.persist( entity1 );
+ session.persist( rootEntity );
+
+ backendMock.expectWorks( IndexedEntity.INDEX )
+ .add( "1", b -> b
+ .field( "string", "smth" )
+ );
+ backendMock.expectWorks( RootEntity.INDEX )
+ .add( "1", b -> b
+ .objectField( "entityShallow", b1 -> b1.field( "string", "smth" ) )
+ .objectField( "entityMapped", b1 -> b1.field( "string", "smth" ) )
+ );
+ } );
+ with( sessionFactory ).runInTransaction( session -> {
+ IndexedEntity entity1 = session.get( IndexedEntity.class, 1 );
+ assertThat( entity1.string ).isEqualTo( "smth" );
+ assertThat( entity1.amountDifference ).isEqualTo( 10 );
+ } );
+ }
+
+ @Entity(name = "root_entity")
+ @Indexed(index = RootEntity.INDEX)
+ public static final class RootEntity {
+
+ static final String INDEX = "RootEntity";
+
+ @Id
+ public Integer id;
+
+ @IndexedEmbedded
+ @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
+ @ManyToOne
+ public IndexedEntity entityShallow;
+
+ @IndexedEmbedded
+ @ManyToOne
+ public IndexedEntity entityMapped;
+
+ }
+
+ @Entity(name = "indexed")
+ @Indexed(index = IndexedEntity.INDEX)
+ public static final class IndexedEntity {
+
+ static final String INDEX = "IndexedEntity";
+
+ @Id
+ public Integer id;
+
+ @FullTextField
+ public String string;
+
+ public int amount1;
+ public int amount2;
+
+ @Formula("amount2 - amount1")
+ public int amountDifference;
+
+ @OneToMany(mappedBy = "entityMapped")
+ Set<RootEntity> rootEntities = new HashSet<>();
+
+ }
+}
diff --git a/test/java/org/hibernate/search/integrationtest/mapper/orm/model/GenericPropertyIT.java b/test/java/org/hibernate/search/integrationtest/mapper/orm/model/GenericPropertyIT.java
index 442af1d773..91fa3b5f36 100644
--- a/test/java/org/hibernate/search/integrationtest/mapper/orm/model/GenericPropertyIT.java
Expand Down
Loading