I have below entity classes:
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Entity1 {
//other variables
@Id
@Column(name="ID")
private String id;
@OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "entity1")
@ToString.Exclude
@EqualsAndHashCode.Exclude
private Entity2 entity2;
}
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Entity2 {
//other variables
@Id
@Column(name = "ID", unique = true, nullable = false)
private String id;
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "ID")
@MapsId
@ToString.Exclude
@EqualsAndHashCode.Exclude
private Entity1 entity1;
}
I am using Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable);
from JpaSpecificationExecutor<T>
interface to query the database.
Now I want to fetch data only from table associated with Entity1 and not from Entity2.
But findAll() is fetching data from both the tables.
Also I do not want to use @Query.
Can anyone please suggest how I can update my code to fetch data only from Entity1 table given that I need to store and update the data on both tables using save() method.
Let me know if any more details are required.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…