Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Hibernite忽略关系onetomany和load集合中的lazy fetchtype_Spring_Hibernate_Spring Data Jpa_Lazy Loading - Fatal编程技术网

Spring Hibernite忽略关系onetomany和load集合中的lazy fetchtype

Spring Hibernite忽略关系onetomany和load集合中的lazy fetchtype,spring,hibernate,spring-data-jpa,lazy-loading,Spring,Hibernate,Spring Data Jpa,Lazy Loading,在spring boot 2上的web应用程序中,我有一个实体,其关系为onetomany。 我不想接收这些实体。但我明白了。 我切换了spring.jpa.open in view=false。 在dao层中,我使用spring数据jpa和方法getById(),getAll() 我的实体类: @Entity @Table(name = "project", schema = "ci_crm") @Data @NoArgsConstructor public class ProjectEnti

在spring boot 2上的web应用程序中,我有一个实体,其关系为onetomany。 我不想接收这些实体。但我明白了。 我切换了spring.jpa.open in view=false。 在dao层中,我使用spring数据jpa和方法getById()getAll()

我的实体类:

@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;

@实体
@表(name=“project”,schema=“ci_crm”)
@资料
@诺尔格构装师
公共类项目实体{`
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私有int-id;
@许多酮
@JoinColumn(name=“公司id”)
私人公司实体公司;
@许多酮
@JoinColumn(name=“user\u id”)
私有用户实体用户;
@OneToMany(mappedBy=“项目”)
私人名单;
@OneToMany(mappedBy=“项目”)
私有列表通知列表;
@OneToMany(mappedBy=“项目”)
私人名单;
那么,如何修复它呢

问题已解决:
问题出现在service layaer中。整个类中都有一个注释@Transactional。

这可能是因为在spring boot项目中创建实体管理器的方式。spring jpa使用实体管理器创建查询,如果查询是由实体管理器生成的,Hibernate将忽略获取模式

请参阅下面的主题

FetchMode如何在Spring数据JPA中工作https://stackoverflow.com/questions/29602386/how-does-the-fetchmode-work-in-spring-data-jpa