I've abstract class:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class A {
...
}
and few extending classes, like:
@Entity
public class B extends A {
...
}
I also have third entity:
@Entity
public class C {
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private A objectA;
...
}
And the question is, how can I construct Spring Data JPA finder in C entity repository to query only objects extending A with desired type?
You can use the name of discriminator value which you've 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With