Spring type query JPA data

I have an abstract class:

@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class A { ... } 

and several extension classes, for example:

 @Entity public class B extends A { ... } 

I also have a third object:

 @Entity public class C { @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) private A objectA; ... } 

And the question is, how can I build a Spring Data JPA finder in the C object repository to query only objects that extend A with the desired type?

+7
java spring-data spring-data-jpa jpa
source share
1 answer

You can use the name of the discriminator value that you defined "type"

 @Entity @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) @Table(name = "abc") public abstract class Abc { .... ------------------------------------------- @Query("select a from Abc a where type = ?1") List<Abc> findByType(String typeValue); 
+7
source share

All Articles