fetch lazy 详解(一)

来源:互联网 发布:高德软件 编辑:程序博客网 时间:2024/05/05 19:01

透过测试发现Hibernate annotation中@ManyToOne,@OneToMany,@OneToOne中lazy的默认值是不同的



@OneToMany 默许Lazy为true


@ManyToOne,@OneToOne 默许lazy为false



在设立@ManyToOne的时分我们正常都市设立Lazy=true



正常不会在@ManyToOne,@OneToOne思忖这个问题



但现实hibernate进展load是时分是把一边也load出来的



fetch 和 lazy 重要是用以级联检询的, 而 cascade 和 inverse 重要是用于级联安插和批改的 fetch参数指定了联系关系对象抓取的形式是select查询仍是join查询,select形式时先查询回到要查询的主导对象(列表),再依据联系关系外键 id,每一个对象发一个select查询,获取联系关系的对象,形成n+1次查 询;而join形式,主导对象和联系关系对象用一句外键联系关系的sql与此同时查询出来,不会形成屡次查询。
如若你的联系关系对像样推延加载的,它当然不会去查询联系关系对象。此外,在hql查询中配置文件中设立的join模式是不起作用的(而在全部其余查询模式如get、criteria或再联系关系获取之类都是有效的),会应用 select模式,除非你在hql中拇指定join fetch某个联系关系对象。fetch计策用来定义 get/load一个对象时,何以获取非lazy的对象/会合。 这些参数在Query中无效
本文来源:
我的异常网
Java Exception
Dotnet Exception
Oracle Exception

  • 2000 - org.hibernate.exception.GenericJDBCException: Could not get list of tables from database. Probably a JDBC driver problem
  • 2001 - java.net.ConnectException: Connection refused
  • 2002 - An unexpected error has been detected by HotSpot Virtual Machine
  • 2003 - java.net.BindException: Address already in use: JVM_Bind
  • 2004 - Error testing property name in bean of type null
  • 2005 - java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is
  • 2006 - Can t call commit when autocommit=true
  • 2007 - javax.naming.NameNotFoundException:CustomerLocal not bound
  • 2008 - errhandler抛出异常在errorPage中如何捕获
  • 2009 - java.lang.Error: 无法解析的编译问题
  • 2010 - RTP Handler internal error: javax.media.ControllerErrorEvent
  • 2011 - java.sql.SQLException: 结果集已耗尽
  • 2012 - java.lang.NoClassDefFoundError: org.jivesoftware.smack.MessageListener
  • 2013 - java.lang.ClassNotFoundException: loadFileURL
  • 2014 - java.lang.NumberFormatException: For input string
  • 2015 - Struts error message 的问题
  • 2016 - java.rmi.server.ExportException: Port already in use: 1098; nested exception is