JPA会急切地获取非实体属性吗?(Will JPA eagerly fetch non

系统教程 行业动态 更新时间:2024-06-14 16:57:40
JPA会急切地获取非实体属性吗?(Will JPA eagerly fetch non-entity attributes?)

我想知道在创建常规查询时是否急切地或懒惰地获取诸如Int或Varchar2类的属性。

@Entity @Table(name = "ROOM") public class Room implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "room_id") private Integer id; @Column(name = "number") private String number; @Column(name = "capacity") private Integer capacity; //Will this be fetched eagerly??? @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "building_id") private Building building; ... ... ... }

基本上:

Room room = getRoomById(5); // select room from Room room where room.id = 5; Integer roomCap = room.getCapacity(); //Will this create another query?

或者它已经在room内了?

I want to know if attributes such as Int or Varchar2 are fetched eagerly or lazily when creating a regular query.

@Entity @Table(name = "ROOM") public class Room implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "room_id") private Integer id; @Column(name = "number") private String number; @Column(name = "capacity") private Integer capacity; //Will this be fetched eagerly??? @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "building_id") private Building building; ... ... ... }

Basically:

Room room = getRoomById(5); // select room from Room room where room.id = 5; Integer roomCap = room.getCapacity(); //Will this create another query?

Or will it be inside the room object already?

最满意答案

渴望或懒惰的提取策略适用于您希望从另一个表加载数据而不是属于同一实体或表的列的关系或关联实体。 检索实体时不会获取属于同一实体或表的列或字段,也不会触发单独的查询。

The fetching strategies eager or lazy apply to relationships or associated entities where you want to load the data from another table and not to the columns that are part of the same entity or table. Columns or fields that belong to the same entity or table are fetched when you retrieve the entity and no separate query is fired.

更多推荐

本文发布于:2023-04-13 12:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d1814f34f5da24c08616369f3076c450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:急切   实体   属性   JPA   eagerly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!