hibernate
zhangzhen02
这个作者很懒,什么都没留下…
展开
-
@EntityGraph使用详解
测试时我使用三个类,类图如下实体图如下:@Entity@Table(name = "location")@NamedEntityGraphs({ @NamedEntityGraph(name = "default",attributeNodes = { @NamedAttributeNode(value = "country",subgraph = "country") }, subgraphs = { @NamedSubgraph(name原创 2020-05-12 10:27:13 · 6845 阅读 · 0 评论 -
hibernate+jpa+entityGraph实现懒加载的问题及解决方案
1.hibernate默认懒加载无效?hibernate默认对所有关联关系使用懒加载,但是在springboot使用的过程中,发现多对一,一对一的时候并未实现懒加载,具体问题请看这篇文章2.为什么不使用fetch = FetchType.EAGER或fetch = FetchType.Lazy?单独使用以上两种方式,有很大局限,该设置是写死的。对所有查询都返回一致的关联内容,问题是有些查询需要,有些查询不需要这些关联内容。都用迫切加载造成浪费,都有懒加载又无法满足一定时期的需要,比如使用缓存时。3.原创 2020-05-09 19:32:51 · 934 阅读 · 0 评论 -
使用hibernate 时发现one-to-one与many-to-one的默认不是懒加载
项目中使用到hibernate5,在one-to-one 及many-to-one时,发现不是懒加载。通过ide自动生成发现如下:默认改为急切加载了?于是查看hibernate5.2文档The Hibernate recommendation is to statically mark all associationslazy and to use dynamic fetching ...原创 2020-05-08 15:29:39 · 648 阅读 · 0 评论 -
常用JPQL
Keyword Sample JPQL snippetAnd findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ?2Or findByLastnameOrFirstname … where x.lastname = ?1 or x.firstname = ?2Betwe...原创 2020-04-30 11:27:49 · 181 阅读 · 0 评论 -
hibernate 必会知识点总结
工作中用hibernate比较多,这里做一个系统的总结。一,hibernate工作流程1.读取并解析配置文件2.读取并解析映射信息,创建SessionFactory3.打开Sesssion4.创建事务Transation5.持久化操作6.提交事务7.关闭Session8.关闭SesstionFactory注意:其中sessionFactory是单例的,在服务启动时创建。二,懒...原创 2020-04-08 17:36:00 · 152 阅读 · 0 评论