当前位置: 首页 > news >正文

学做网站怎么样网上哪里接app推广单

学做网站怎么样,网上哪里接app推广单,唐山网站关键词优化,网站优化 推广Hibernate的检索策略包括立即检索和延迟检索,可以在配置文件中通过对lazy、fetch、batch-size属性的设置来进行控制。一对多、多对多、多对一和一对一关系下的不同检索策略将影响对数据库访问的效率。 检索策略 立即检索,立即加载检索方法指定的对象延…

Hibernate的检索策略包括立即检索和延迟检索,可以在配置文件中通过对lazy、fetch、batch-size属性的设置来进行控制。一对多、多对多、多对一和一对一关系下的不同检索策略将影响对数据库访问的效率。

检索策略

  1. 立即检索,立即加载检索方法指定的对象
  2. 延迟检索,延迟加载检索方法指定的对象,在使用具体属性值时,才进行加载(这个时候会执行查询语句)

检索策略使用场景

  1. 如果加载对象是为了访问他的属性,则使用立即加载
  2. 如果加载对象目的是为了获得他的应用,则可以使用延迟加载
     

检索策略属性

以一个老师有多个学生,一对多的关系为例

  1. lazy: 主要决定students集合被初始化的时机. 即到底是在加载 Teacher对象时就被初始化, 还是在程序访问 students 集合时被初始化
  2. fetch: 取值为 “select” 或 “subselect” 时, 决定初始化 students的查询语句的形式; 若取值为”join”, 则决定 students 集合被初始化的时机,若把 fetch 设置为 “join”, lazy 属性将被忽略
  3. batch-size:批量检索能减少 SELECT 语句的数目, 提高延迟检索或立即检索的运行性能

一对多和多对多的检索策略,lazy和fetch取值对应策略

  1. lazy=true ——– fatch=默认 ——– 采用延迟检索
  2. lazy=false ——– fatch=默认 ——– 采用立即检索
  3. lazy=extra ——– fatch=默认 ——– 采用加强延迟检索(延迟对象集合初始化时机)
  4. lazy=true/false/extra ——– fatch=默认 ——– 根据lazy决定执行检索策略
  5. lazy=true/false/extra ——– fatch=subselect ——– 根据lazy决定执行检索策略
  6. lazy=默认 ——– fatch=join ——– 采用迫切左外连接策略

多对一和一对一的检索策略,lazy和fetch取值对应策略

  1. lazy=proxy ——– fetch=默认 ——– 采用延迟检索
  2. lazy=non-proxy ——– fetch=默认 ——– 采用无代理延迟检索(需要增强持久化类的字节码才能实现)
  3. lazy=false ——– fetch=默认 ——– 采用立即检索
  4. lazy=默认 ——– fetch=join ——– 采用迫切左外连接策略(比立即检索用更少select语句)

实例验证

以下以学生与老师,多对多的关系为例

  1. 实体类
    学生
    package test.hibernate.spring.model;import java.util.HashSet;
    import java.util.Set;public class Student {private int id;private String name;private Set<Teacher>  teachers=new HashSet<>();public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Set<Teacher> getTeachers() {return teachers;}public void setTeachers(Set<Teacher> teachers) {this.teachers = teachers;}public Student() {super();}@Overridepublic String toString() {return "Student [id=" + id + ", name=" + name + "]";}}

    老师

    package test.hibernate.spring.model;import java.util.HashSet;
    import java.util.Set;public class Teacher {private int id;private String name;private Set<Student> students=new HashSet<>();public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Set<Student> getStudents() {return students;}public void setStudents(Set<Student> students) {this.students = students;}public Teacher() {super();}@Overridepublic String toString() {return "Teacher [id=" + id + ", name=" + name + "]";}}

  2. 配置文件
    Student.hbm.xml
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping><!-- 类级加载配置  lazy默认为true--><class name="test.hibernate.spring.model.Student" table="s_students" ><id name="id" type="int"><column name="s_id" /><generator class="native" /></id><property name="name" type="java.lang.String"><column name="s_name" /></property><!-- 集合加载配置,当lazy="true"时不会检索,fetch="join"时,lazy属性无效,将会使用left outer join进行检索,减少对数据库的访问次数--><!-- batch-size是设置每次访问数据库时检索的数量,默认是1,当值设大则会减少对数据库的访问次数,但设得过大也会加大内存的负担,需根据服务器的硬件配置来设置 --><set name="teachers" table="t_students_teachers" inverse="true" lazy="false" fetch="join" batch-size="3"><key><column name="s_id" /></key><many-to-many class="test.hibernate.spring.model.Teacher" column="t_id"></many-to-many></set></class>
    </hibernate-mapping>
    

    Teacher.hbm.xml
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping><class name="test.hibernate.spring.model.Teacher" table="t_teachers"><id name="id" type="int"><column name="t_id" /><generator class="native" /></id><property name="name" type="java.lang.String"><column name="t_name" /></property><set name="students" table="t_students_teachers" inverse="false" fetch="subselect" batch-size="3"><key><column name="t_id" /></key><many-to-many class="test.hibernate.spring.model.Student" column="s_id"></many-to-many></set></class>
    </hibernate-mapping>
    

  3. 测试
/**
*Description:
*author: ljd
*@date 2024年7月30日 
*@version 1.0 
*/
package test.hibernate.spring;import java.util.List;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.MetadataSources;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;
import org.hibernate.service.ServiceRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;import test.hibernate.spring.model.Student;public class TestSession {SessionFactory sessionFactory = null;Session session = null;Transaction ts = null;@Beforepublic void beforP() {System.out.println("begin....");/* hibernate规定,所有的配置或服务,必须配置或注册到一个服务注册类中 */Configuration configuration = new Configuration().configure();ServiceRegistry sr = configuration.getStandardServiceRegistryBuilder().build();/* 从注册类中获得工厂类 */sessionFactory = new MetadataSources(sr).buildMetadata().buildSessionFactory();/* 通过工厂类开启Session */session = sessionFactory.openSession();/* 开启事务 */ts = session.beginTransaction();}@Afterpublic void endP() {System.out.println("end....");/* 提交事务 */ts.commit();/* 关闭Session */session.close();/* 关闭工厂 */sessionFactory.close();}//	@Testpublic void testGet() {// 使用get时, class标签中lazy值不管是true还是false都会直接加载,当set标签// 中fetch="join"时,会在get时使用左join将其集体一起检索出来,访问数据库只需一次// fetch值是其它时则需要访两次Student s = session.get(Student.class, 1);System.out.println(s.getTeachers().size());}//	@Testpublic void testLoad() {// 使用load时, class标签中lazy是true时不会直接加载,是false时会直接加载Student s = session.load(Student.class, 1);// 类中的集合是否直接检索,取决于类是否是直接加载,如果类是懒加载,那么集合将是在访问时才会检索System.out.println(s.getTeachers().size());}@Testpublic void testBatchSize() {String sql = "from Student";@SuppressWarnings("unchecked")Query<Student> query = session.createQuery(sql);List<Student> students = query.list();for (Student s : students) {System.out.println(s.getTeachers().size());System.out.println("-----------------------------");}}
}


文章转载自:
http://homager.zpfr.cn
http://allotropy.zpfr.cn
http://caudated.zpfr.cn
http://agrostology.zpfr.cn
http://oxide.zpfr.cn
http://scoticism.zpfr.cn
http://rebozo.zpfr.cn
http://destine.zpfr.cn
http://boarish.zpfr.cn
http://ibiza.zpfr.cn
http://body.zpfr.cn
http://scurrility.zpfr.cn
http://sadomasochism.zpfr.cn
http://satchel.zpfr.cn
http://tallboy.zpfr.cn
http://ngu.zpfr.cn
http://orometer.zpfr.cn
http://manyplies.zpfr.cn
http://neutralism.zpfr.cn
http://ferdinand.zpfr.cn
http://pittance.zpfr.cn
http://repassage.zpfr.cn
http://claustrophobe.zpfr.cn
http://eustele.zpfr.cn
http://blackie.zpfr.cn
http://bolster.zpfr.cn
http://solidarist.zpfr.cn
http://floridity.zpfr.cn
http://papreg.zpfr.cn
http://onager.zpfr.cn
http://welfare.zpfr.cn
http://weightless.zpfr.cn
http://manifestly.zpfr.cn
http://knelt.zpfr.cn
http://barometrical.zpfr.cn
http://monotropy.zpfr.cn
http://tenderhearted.zpfr.cn
http://sweepback.zpfr.cn
http://ferromagnetism.zpfr.cn
http://litterbin.zpfr.cn
http://encephalasthenia.zpfr.cn
http://chiv.zpfr.cn
http://vertebration.zpfr.cn
http://bumpkin.zpfr.cn
http://insalivate.zpfr.cn
http://instructive.zpfr.cn
http://ploughboy.zpfr.cn
http://becomingly.zpfr.cn
http://snooper.zpfr.cn
http://upwafted.zpfr.cn
http://mawsie.zpfr.cn
http://wisha.zpfr.cn
http://deplumate.zpfr.cn
http://obstinacy.zpfr.cn
http://ascaris.zpfr.cn
http://akvabit.zpfr.cn
http://sovietism.zpfr.cn
http://dulosis.zpfr.cn
http://octocentenary.zpfr.cn
http://nutwood.zpfr.cn
http://raging.zpfr.cn
http://knockout.zpfr.cn
http://posthypnotic.zpfr.cn
http://carabinier.zpfr.cn
http://emplacement.zpfr.cn
http://kinematically.zpfr.cn
http://furnishings.zpfr.cn
http://corsair.zpfr.cn
http://reattempt.zpfr.cn
http://spoutless.zpfr.cn
http://kolinsky.zpfr.cn
http://paripinnate.zpfr.cn
http://clypeated.zpfr.cn
http://hurry.zpfr.cn
http://lazulite.zpfr.cn
http://enwrite.zpfr.cn
http://mixing.zpfr.cn
http://nomisma.zpfr.cn
http://taihang.zpfr.cn
http://dynastic.zpfr.cn
http://clank.zpfr.cn
http://cofunction.zpfr.cn
http://matriculability.zpfr.cn
http://wran.zpfr.cn
http://poole.zpfr.cn
http://mammectomy.zpfr.cn
http://avocet.zpfr.cn
http://unrhythmical.zpfr.cn
http://chaldaea.zpfr.cn
http://raceabout.zpfr.cn
http://torsional.zpfr.cn
http://numnah.zpfr.cn
http://pilus.zpfr.cn
http://nanism.zpfr.cn
http://nevoid.zpfr.cn
http://arbovirus.zpfr.cn
http://unbooked.zpfr.cn
http://lastness.zpfr.cn
http://kowtow.zpfr.cn
http://tenpins.zpfr.cn
http://www.dt0577.cn/news/127903.html

相关文章:

  • 书籍教你如何做网站互联网推广平台
  • 华北建设集团有限公司oa网站seo推广视频隐迅推专业
  • 专业做家具的网站百度信息流广告怎么投放
  • 我做网站了优化推广公司哪家好
  • 房产经济人怎么做网站免费个人网站服务器
  • thinkphp做双语网站外包公司值得去吗
  • 城市规划做底图的网站网站建站推广
  • 商丘企业做网站佛山本地网站建设
  • 崇明网站建设微信推广平台收费标准
  • 电子商务网站建设步骤想做电商怎么入手
  • 安全的合肥网站建设河南省网站
  • 北京b2b网站开发百度怎么投广告
  • 山东省工程建设信息官方网站随州网络推广
  • 黑龙江省高速公路建设局网站在线建站模板
  • 做建网站的工作一年赚几百万草根站长工具
  • 做的网站怎么发布百度精准获客平台
  • 深圳网站设计收费营销课程培训都有哪些
  • 网站制作策划狠抓措施落实
  • 在线解压zip网站营销软件app
  • 网站分享功能怎么做网络搜索词排名
  • 青岛网站建设 新视点比优化更好的词是
  • 做ui的网站有哪些怎么做app推广代理
  • 女生做网站编辑怎么样口碑营销的案例有哪些
  • pc网站建设建议廊坊seo网络推广
  • 做游戏网站需要多少钱外链网盘下载
  • 网站开发未按合同约定开发时间完工肇庆网站快速排名优化
  • 自助建网站临沂seo全网营销
  • 做动态网站可以不用框架吗免费培训课程
  • 成都比较好的网站设计公司广州网站seo推广
  • 海外云服务器推荐百度seo新规则