lazy-loading

In Spring with jpa/hibernate, how do I keep a session open to avoid lazy initialization exceptions?

时间秒杀一切 提交于 2019-11-27 11:42:56
I currently mark collections in entity beans as eager to avoid getting a lazy initialization exception when I try to access the collection properties after loading the bean with the EntityManager. If I instead leave the collection as lazy loading, how do I keep a session open? I thought about trying @Transactional, but even if that worked I wouldn't want to do it because it doesn't seem right to leave a transaction open over a long method. https://www.hibernate.org/43.html Basically, you have a few options. -You can use the "open session in view" pattern where you use a filter/interceptor/AOP

Doctrine 2 ArrayCollection filter method

狂风中的少年 提交于 2019-11-27 11:05:40
Can I filter out results from an arrayCollection in Doctrine 2 while using lazy loading? For example, // users = ArrayCollection with User entities containing an "active" property $customer->users->filter('active' => TRUE)->first() It's unclear for me how the filter method is actually used. FredRoger The Boris Guéry answer's at this post, may help you: Doctrine 2, query inside entities $idsToFilter = array(1,2,3,4); $member->getComments()->filter( function($entry) use ($idsToFilter) { return in_array($entry->getId(), $idsToFilter); } ); Ryan Doctrine now has Criteria which offers a single API

SDWebImage does not load remote images until scroll

[亡魂溺海] 提交于 2019-11-27 10:38:27
问题 I am using SDWebImage library to load remote images into a table view which uses a custom cell class i have created. I simply use [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"loading.jpg"]]; in cellForRowAtIndexPath: Now the problem is it loads images in the visible cells only and not for cells that are offscreen for which i have to scroll up and down to make them load. Is there any way i can load all images without having to scroll the table view. Thanks in

Show activity Indicator while loading a lazy loaded Module in Angular 2

橙三吉。 提交于 2019-11-27 10:32:20
问题 My scenario is as follows. I have a menu, with multiple options. Each menu should be shown depending on user permissions (already solved), most menu items are encapsulated as modules, and most of the modules are lazy loaded, so when a user clicks a menu item the first time, it loads (up to here everything works well), now my requirement is, in order to give a better user experience, I need to show activity indicator after user clicks a menu item while the lazy loaded module is loading. Up to

Hibernate: best practice to pull all lazy collections

随声附和 提交于 2019-11-27 10:19:20
What I have: @Entity public class MyEntity { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "myentiy_id") private List<Address> addreses; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "myentiy_id") private List<Person> persons; //.... } public void handle() { Session session = createNewSession(); MyEntity entity = (MyEntity) session.get(MyEntity.class, entityId); proceed(session); // FLUSH, COMMIT, CLOSE session! Utils.objectToJson(entity); //TROUBLES, because it can't convert to

Implicitly lazy static members in Swift

天涯浪子 提交于 2019-11-27 10:06:53
问题 I just noticed that static members of Swift structs are implicitly lazy . For instance, this will only call the init once: class Baz { init(){ print("initializing a Baz") } } struct Foo { static let bar = Baz() } var z = Foo.bar z = Foo.bar What's the rationale behind this? What if I want the opposite behaviour? 回答1: The static property defines a "type property", one that is instantiated once and only once. As you note, this happens lazily, as statics behave like globals. And as The Swift

infinite scroll with ember.js (lazy loading)

狂风中的少年 提交于 2019-11-27 10:03:43
I have a view where there can be a large number of items for the user to scroll through and I'd like to implement infinite scrolling to enable progressive loading of the content. It looks like some folks have done pagination but Google doesn't bring up anyone discussing how they've done infinite lists with Ember/Ember Data. Anyone already worked through this and have a blog post/example code to share? Were you aware of the newly released Ember.ListView component? https://github.com/emberjs/list-view It was announced at the February San Francisco Ember Meetup. Here's a slidedeck from Erik Bryn,

Angular 4 Lazy loading with named router-outlet not working

爱⌒轻易说出口 提交于 2019-11-27 09:09:13
I have a problem with lazy loading not about to route to a named router-outlet. Can someone look at where I when wrong? I have a mainpage where there is a link to Product -> default router outlet and Product Detail -> named router outlet. <div> <div><a [routerLink]="['product']"> Product </a> </div> <div><a [routerLink]="['productdetail',{outlets:{productdetail: 'detail'}}]"> Product Detail </a> </div> <div> <router-outlet></router-outlet></div> <div> <router-outlet name="detail"></router-outlet> </div> Below is the plunker code. Plunker Code This is known bug, you can track the issue here The

Hibernate lazy-load application design

蓝咒 提交于 2019-11-27 08:59:03
问题 I tend to use Hibernate in combination with Spring framework and it's declarative transaction demarcation capabilities (e.g., @Transactional). As we all known, hibernate tries to be as non-invasive and as transparent as possible, however this proves a bit more challenging when employing lazy-loaded relationships. I see a number of design alternatives with different levels of transparency. Make relationships not lazy-loaded (e.g., fetchType=FetchType.EAGER) This vioalites the entire idea of

org.hibernate.LazyInitializationException at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel

一世执手 提交于 2019-11-27 08:24:28
Despite of FetchType.EAGER and JOIN FETCH , I get a LazyInitalizationException while adding some objects to a @ManyToMany collection via a JSF UISelectMany component such as in my case the <p:selectManyMenu> . The @Entity IdentUser , with FetchType.EAGER : @Column(name = "EMPLOYERS") @ManyToMany(fetch = FetchType.EAGER, cascade= CascadeType.ALL) @JoinTable(name = "USER_COMPANY", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "COMPANY_ID") }) private Set<Company> employers = new HashSet<Company>(); The @Entity Company , with FetchType.EAGER :