Skip to content

Commit 179ad11

Browse files
fekynkoMartin Fekete
and
Martin Fekete
authored
fixed querying by super class attribute (#173)
Co-authored-by: Martin Fekete <[email protected]>
1 parent 9be2eca commit 179ad11

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

rsql-common/src/main/java/io/github/perplexhub/rsql/RSQLVisitorBase.java

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import lombok.Getter;
1717
import org.hibernate.metamodel.model.domain.ManagedDomainType;
18+
import org.hibernate.metamodel.model.domain.PersistentAttribute;
1819
import org.springframework.core.convert.ConversionFailedException;
1920
import org.springframework.core.convert.support.ConfigurableConversionService;
2021
import org.springframework.orm.jpa.vendor.Database;
@@ -58,6 +59,10 @@ public static Database getDatabase(EntityManager entityManager) {
5859
// W/A found here: https://hibernate.atlassian.net/browse/HHH-18569
5960
// breaking change on hibernate side: https://github.com/hibernate/hibernate-orm/pull/6924#discussion_r1250474422
6061
if (classMetadata instanceof ManagedDomainType managedDomainType) {
62+
PersistentAttribute<T,?> attribute = managedDomainType.findAttribute( property );
63+
if ( attribute != null ) {
64+
return attribute;
65+
}
6166
return managedDomainType.findSubTypesAttribute(property);
6267
}
6368
return classMetadata.getAttribute(property);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.perplexhub.rsql.repository.jpa;
2+
3+
import io.github.perplexhub.rsql.model.AdminProject;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6+
7+
public interface AdminProjectRepository extends JpaRepository<AdminProject, Integer>, JpaSpecificationExecutor<AdminProject> {
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.perplexhub.rsql.repository.jpa;
2+
3+
import io.github.perplexhub.rsql.model.Project;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6+
7+
public interface ProjectRepository extends JpaRepository<Project, Integer>, JpaSpecificationExecutor<Project> {
8+
9+
}

rsql-jpa/src/test/java/io/github/perplexhub/rsql/RSQLJPASupportTest.java

+22
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
import java.util.*;
1919

2020
import io.github.perplexhub.rsql.custom.CustomType;
21+
import io.github.perplexhub.rsql.model.Project;
22+
import io.github.perplexhub.rsql.model.AdminProject;
2123
import io.github.perplexhub.rsql.model.account.AccountEntity;
2224
import io.github.perplexhub.rsql.model.account.AddressEntity;
2325
import io.github.perplexhub.rsql.model.account.AddressHistoryEntity;
2426
import io.github.perplexhub.rsql.repository.jpa.AccountRepository;
27+
import io.github.perplexhub.rsql.repository.jpa.AdminProjectRepository;
28+
import io.github.perplexhub.rsql.repository.jpa.ProjectRepository;
2529
import io.github.perplexhub.rsql.repository.jpa.custom.CustomTypeRepository;
2630
import io.github.perplexhub.rsql.custom.EntityWithCustomType;
2731
import jakarta.persistence.criteria.Expression;
@@ -70,6 +74,12 @@ class RSQLJPASupportTest {
7074
@Autowired
7175
private CustomTypeRepository customTypeRepository;
7276

77+
@Autowired
78+
private AdminProjectRepository adminProjectRepository;
79+
80+
@Autowired
81+
private ProjectRepository projectRepository;
82+
7383
@Autowired
7484
AccountRepository accountRepository;
7585

@@ -1441,6 +1451,18 @@ void testSearchWithReducedPathUsingRSQLMapping() {
14411451
Assertions.assertThat(result).hasSize(1);
14421452
}
14431453

1454+
@Test
1455+
void testSearchByParentAttribute() {
1456+
List<AdminProject> result = adminProjectRepository.findAll(RSQLJPASupport.rsql("name=='someProjectName'"));
1457+
Assertions.assertThat(result).hasSize(1);
1458+
}
1459+
1460+
@Test
1461+
void testSearchBySubtypeAttribute() {
1462+
List<Project> result = projectRepository.findAll(RSQLJPASupport.rsql("departmentName==someDepartmentName"));
1463+
Assertions.assertThat(result).hasSize(1);
1464+
}
1465+
14441466
@BeforeEach
14451467
void setUp() {
14461468
getPropertyWhitelist().clear();

0 commit comments

Comments
 (0)