When the project was developed, the database operation was performed in a job with lazy loading, but the following errorOrg.hibernate.LazyInitializationException:failed to lazily initialize a collection of role: ..., no session or Sessio N was closedLazy loading is configured in the project using Hibernate annotations, not an XML configuration file,The following
When performing O-R mapping, we often encounter loading a graph of objects. This is the lazy loading application scenario. You don't want to load all the table objects associated with the database to the memory at a time?
Available methods include:
1. Lazy Initialization
Simply put, it is used to determine whether
In swift, lazy loading is called only once, and if the value is emptied or set to nil, the method in lazy loading is not recalled again when called again1. Basic Use Method // * * Lazy loading of Swift, only once var label:u
Preload: Loading pictures in advance, rendering them directly from the local cache when they need to be viewed. The nature of the two technologies: the behavior is reversed, one is in advance, the other is slow or not even loaded. Lazy load on the front end of the server has a certain ease of pressure, preload will increase the front-end pressure on the server. Lazy
;hibernatethreadfilterfilter-name>
filter-class>org.sunxin.struts2.filter.hibernatethreadfilterfilter-class >
filter>
filter-mapping>
filter-name>hibernatethreadfilterfilter-name>
url-pattern>/*url-pattern>
filter-mapping>
This opens the session before accessing the background code and closes the session after accessing the backend code.2. Manage Hibernate with spring:I. Spring provides us with such a filter so tha
Elecuser = null;if (list!=null list.size () >0) {Elecuser = list.get (0);}/*** * Resolving lazy Load Exceptions*/Hibernate. Initialize (Elecuser.getelecroles ());return Elecuser;}Scenario Three: In ElecUser.hbm.xml, add lazy= "false" to query the user at the same time, immediately retrieve the query user associated role collection:"Elecroles" table="Elec_user_role" inverse="true"
in fact, when the default is not to write is lazy loading, but some more specific laze=true/false only these two values, if set to False, is the load method will still execute the SQL statement, load and lazy with the use of
Instance
1 set to True
"-//hibernate/hibernate Mapping DTD 3.0//en""Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
voiddestroy () {}}Add this filter configuration to Web. xml:Filter> Filter-name>HibernatethreadfilterFilter-name> Filter-class>Org.sunxin.struts2.filter.HibernateThreadFilterFilter-class> Filter> filter-mapping> Filter-name>HibernatethreadfilterFilter-name> Url-pattern>/*Url-pattern> filter-mapping> This opens the session before accessing the background code and closes the session after accessing the backend code.2. Manage Hib
properties and methods to complete some operations. This anonymous function self-executing constructed monomer mode is widely used in many JS libraries, but there is still a problem, if we do not need to use the object when loading the page, and the creation of the object is more expensive (such as the need for a large number of calculations or the need to access the DOM tree and its properties, etc.), It is reasonable to create it when it is needed,
Cause:When using Hibernate to query an object, a lazy load exception will occur if the session is closed and the collection or object associated with the object is called.Solution:Programme one:Before the session closes, query the collection or object associated with the object, all of which are added on the business layer's methods:1 Publicelecuser finduserbylogonname (String name) {2 3String condition =
Reprint: Please specify the original link and the author's name ' Little Small 'Will the applet really replace everything? QQ Group: 139128168← Click Add GroupIn small programs, lazy loading effect is a headache, because the small program is completely unable to manipulate the DOM, so the location of the operation in the small program, become extremely difficult ~ ~See Special effects First:We will split it
1. First define the style that needs lazy loading;Class= "Lazyload"2. Set the initial transparency to 0.1;. lazyload{Filter:alpha (opacity=10); -moz-opacity:0.1; opacity:0.1;}3. Place the real address that really needs to be loaded in the DATA-SRC attribute;src= "lazy loading
1. PrefaceSometimes we have this demand, when the page has a lot of pictures, we do not want to load the picture at once, but want to when the browser slide to the specified location and then load, which can save bandwidth, it can also help reduce server load. Then this demand needs to take advantage of lazyload.Jquery_lazyload.js is an extension based on JQ and needs to be used after the introduction of JQ.2. Use method
DefinedPicture delay loading is also known as lazy loading, loading some pictures when loading pictures late or qualifying certain conditions, usually for pages with more pictures. You can reduce the number of requests or delay the number of requests to optimize performance.
Lazy loading of JavaScript is one of those problems on the web that makes you want to go crazy to find solutions.
Many people say "then use defer" or "async", and even some people say, "Put your JavaScript code at the bottom of the page code."
None of these methods can solve the problem of loading external JS after the Web page is completely loaded. The above m
Lazy loading of hibernateCause:
When you use hibernate to query an object, if the Session is closed and you call the set or object associated with the object, a lazy loading exception will occur!
Solution:
Solution 1:
Before the Session is closed, query the set or object associated with the object, and add all the meth
Picture preloading mechanism principle: is the early loading of pictures, to the front-end server has some pressure.Image delay Loading principle: In order to alleviate the front-end server pressure, delay loading pictures, meet the conditions of the time to load the picture, of course, does not meet the conditions will not load the picture.Preload implementation
This article describes the method of PHP implementation lazy loading. Share to everyone for your reference. The specific analysis is as follows:
Ordinary PHP loading is through the include (), require () and other methods to load the external file, and then invoke the method through the instance or call the static method directly, and this way to write the intro
); Iscanloaddata (); }/** * Can load data * conditions that can load data: * 1. View already initialized * 2. View visible to User */ Private void Iscanloaddata() {if(Getuservisiblehint () isinit) {lazyload (); } }/** * View destroyed when the state of fragment is initialized to False */ @Override Public void Ondestroyview() {Super. Ondestroyview (); Isinit =false; }protected void Showtoast(String message) {if(! Textutil
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.