-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type information when using dynamic projection and generic reposi…
…tory (#149) Co-authored-by: Réda Housni Alaoui <[email protected]>
- Loading branch information
1 parent
825f5fb
commit 4bcc022
Showing
5 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
...m/cosium/spring/data/jpa/entity/graph/repository/query/EntityGraphAwareJpaParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...a/com/cosium/spring/data/jpa/entity/graph/repository/DynamicProjectionRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cosium.spring.data.jpa.entity.graph.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.cosium.spring.data.jpa.entity.graph.BaseTest; | ||
import com.cosium.spring.data.jpa.entity.graph.sample.Brand; | ||
import com.github.springtestdbunit.annotation.DatabaseSetup; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import java.io.Serializable; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.data.repository.NoRepositoryBean; | ||
import org.springframework.data.repository.Repository; | ||
|
||
@DatabaseSetup(BaseTest.DATASET) | ||
class DynamicProjectionRepositoryTest extends BaseTest { | ||
|
||
@Inject private BrandRepository repository; | ||
|
||
@Test | ||
@Transactional | ||
@DisplayName("dynamic projections should work when you have a super class with generics") | ||
void test1() { | ||
var result = repository.findById(1L, Brand.class); | ||
assertThat(result).map(Brand::getId).isPresent(); | ||
} | ||
|
||
@NoRepositoryBean | ||
public interface EntityGraphBaseRepository<T, I extends Serializable> extends Repository<T, I> { | ||
<X> Optional<X> findById(I id, Class<X> clazz); | ||
} | ||
|
||
@org.springframework.stereotype.Repository | ||
public interface BrandRepository extends EntityGraphBaseRepository<Brand, Long> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters