There is this JPA Entity (let's call it Foo
) that I use to display on the FrontEnd. The Entity is linked to another entity by a join (Let's call it Bar
).
So the backstory here is that I don't need Bar
in the FrontEnd call (When calling the Foo
Entity/ties), I only need it for a BackEnd call (When calling the Foo
Entity/ties). Is there a way to conditionally exclude the joined Bar entity when calling Foo
entities via the JPA FooRepository
?
PS: Let's say one Foo
entity is linked to a 1000 Bar
entities and I don't want it to delay displaying in the FrontEnd because of entities that are not going to be useful in the FrontEnd.
The below is the JPA Entity for Foo
public class Foo implements Serializable {
@Id
@Column(name = "id")
private BigInteger id;
@Column(name = "name")
private String name;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumns({
@JoinColumn(name = "id" , referencedColumnName = "foo_id")
})
private List<Bar> barList;
}
And this is the JPA Entity for Bar
public class Bar implements Serializable {
@Id
@Column(name = "key")
private BigInteger key;
@Column(name = "foo_id")
private BigInteger fooId;
@Column(name = "back_code")
private String backCode;
@Column(name = "date_cap")
private Date dateCap;
@Column(name = "hash")
private String hash;
}
Below is the JPA Repository for Foo, with no custom methods, I am only using findAll()
and findById()
public interface FooRepository extends JpaRepository<Foo, BigInteger>{
}