0

in my web app on spring boot 2 i have an entity with ralations onetomany. I do not want to receive these entities. but i get them. i switched of spring.jpa.open-in-view=false. in dao layer i use spring data jpa and methods getById(), getAll() .

my entity class:

@Entity
@Table(name = "project", schema = "ci_crm")
@Data
@NoArgsConstructor
public class ProjectEntity {`

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @ManyToOne
    @JoinColumn(name = "company_id")
    private CompanyEntity company;
    @ManyToOne
    @JoinColumn(name = "user_id")
    private UserEntity user;
    @OneToMany(mappedBy = "project")
    private List<MilestoneEntity> milestoneList;
    @OneToMany(mappedBy = "project")
    private List<NotificationEntity> notificationList;
    @OneToMany(mappedBy = "project")
    private List<CommentEntity> commentList;

So, how fix it?

the problem is solved: the problem was in service layaer. there was an annotation @Transactional throughout the class.

1 Answers1

0

It could be because of the way entity manager was created in your spring boot project. Spring-jpa creates the query using the entity manager and Hibernate will ignore the fetch mode if the query was built by the entity manager.

Please see the below topic

How does the FetchMode work in Spring Data JPA - https://stackoverflow.com/questions/29602386/how-does-the-fetchmode-work-in-spring-data-jpa