Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import lombok.Getter;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.orm.jpa.vendor.Database;
Expand Down Expand Up @@ -58,6 +59,10 @@ public static Database getDatabase(EntityManager entityManager) {
// W/A found here: https://hibernate.atlassian.net/browse/HHH-18569
// breaking change on hibernate side: https://github.com/hibernate/hibernate-orm/pull/6924#discussion_r1250474422
if (classMetadata instanceof ManagedDomainType managedDomainType) {
PersistentAttribute<T,?> attribute = managedDomainType.findAttribute( property );
if ( attribute != null ) {
return attribute;
}
return managedDomainType.findSubTypesAttribute(property);
}
return classMetadata.getAttribute(property);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.perplexhub.rsql.repository.jpa;

import io.github.perplexhub.rsql.model.AdminProject;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

public interface AdminProjectRepository extends JpaRepository<AdminProject, Integer>, JpaSpecificationExecutor<AdminProject> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.perplexhub.rsql.repository.jpa;

import io.github.perplexhub.rsql.model.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

public interface ProjectRepository extends JpaRepository<Project, Integer>, JpaSpecificationExecutor<Project> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
import java.util.*;

import io.github.perplexhub.rsql.custom.CustomType;
import io.github.perplexhub.rsql.model.Project;
import io.github.perplexhub.rsql.model.AdminProject;
import io.github.perplexhub.rsql.model.account.AccountEntity;
import io.github.perplexhub.rsql.model.account.AddressEntity;
import io.github.perplexhub.rsql.model.account.AddressHistoryEntity;
import io.github.perplexhub.rsql.repository.jpa.AccountRepository;
import io.github.perplexhub.rsql.repository.jpa.AdminProjectRepository;
import io.github.perplexhub.rsql.repository.jpa.ProjectRepository;
import io.github.perplexhub.rsql.repository.jpa.custom.CustomTypeRepository;
import io.github.perplexhub.rsql.custom.EntityWithCustomType;
import jakarta.persistence.criteria.Expression;
Expand Down Expand Up @@ -70,6 +74,12 @@ class RSQLJPASupportTest {
@Autowired
private CustomTypeRepository customTypeRepository;

@Autowired
private AdminProjectRepository adminProjectRepository;

@Autowired
private ProjectRepository projectRepository;

@Autowired
AccountRepository accountRepository;

Expand Down Expand Up @@ -1441,6 +1451,18 @@ void testSearchWithReducedPathUsingRSQLMapping() {
Assertions.assertThat(result).hasSize(1);
}

@Test
void testSearchByParentAttribute() {
List<AdminProject> result = adminProjectRepository.findAll(RSQLJPASupport.rsql("name=='someProjectName'"));
Assertions.assertThat(result).hasSize(1);
}

@Test
void testSearchBySubtypeAttribute() {
List<Project> result = projectRepository.findAll(RSQLJPASupport.rsql("departmentName==someDepartmentName"));
Assertions.assertThat(result).hasSize(1);
}

@BeforeEach
void setUp() {
getPropertyWhitelist().clear();
Expand Down