lazy-loading

JPA equivalent command to Hibernate.initialize

久未见 提交于 2019-12-06 11:45:49
I have a Lazy collection that I want to initialize at will in my service/controller. At this moment I can do: Hibernate.initialize( myEntity.getListOfThings() ); This command is hibernate dependent and does not make the implementation of JPA transparent. Is there a JPA elegant way of doing this? Master Slave No, there's no JPA equivalent. You can learn if the object is loaded and than use one of the two options, either accessing the properties while the object is still attached to persistence context, what I typically see is calling size, just for the sake of initializing the collection

NHibernate serializing lazy-loaded entities with WCF

余生颓废 提交于 2019-12-06 11:35:56
I'm trying to send NH entities through the wire using WCF. I've got a complex graph of lazy-loaded objects.. I tried to implement a custom DataContractSurrogate to force initialization when serializing. Here is the code : public class HibernateDataContractSurrogate : IDataContractSurrogate { public HibernateDataContractSurrogate() { } public Type GetDataContractType(Type type) { // Serialize proxies as the base type if (typeof(INHibernateProxy).IsAssignableFrom(type)) { type = type.GetType().BaseType; } // Serialize persistent collections as the collection interface type if (typeof

CodeIgniter lazy-loading libraries/models/etc

纵然是瞬间 提交于 2019-12-06 11:26:39
When writing CodeIgniter applications my controller actions tend to begin with a few lines as below: $this->load->model('abc_model'); $this->load->library('ijk'); And then (just for completeness) they're used as follows: $this->abc_model->fetch_123(); $this->ijk->do_something(); Would there be anything too wrong about extending MY_Controller so that the following was possible? $this->model('zbc_model')->fetch_stuff(); $this->library('ijk')->do_something(); Pros: Classes aren't loaded until they're actually used Wouldn't need to auto-load any classes using config/autoload.php Slightly cleaner

Java: Lazy loading Singleton and reflection attack?

做~自己de王妃 提交于 2019-12-06 10:47:27
If I implement a Singleton either through holder idiom or double checked locking, but instead of calling 'getInstance()', use reflection to instantiate it, and then call 'getInstance()' on it, this would create two instances, breaking the pattern. So I add a static 'counter' member to the class, increment it in the class's private constructor, and throw an exception if it crosses '1'. But in that case, if I first instantiate through reflection, nobody else would be able to call 'getInstance()' without throwing an Exception. So how do I lazy load a Singleton yet prevent it from this attack? (I

EF4.3 Code-First, MVC, Lazy Loading After Attaching in POST Action

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:56:53
问题 I'm using Entity Framework 4.3 with Code-First in an MVC 3 application. I have a POST action that gets an entity as its' parameter, and then marks the entity as modified to update the database. It's a Document entity that has a reference to a File Type. [HttpPost] public ActionResult Example(Document model) { // fileType is null, as expected var fileType = model.FileType; // attach and mark the entity as modified, save changes Context.Entry(model).State = EntityState.Modified; Context

How can we use Provider in Pipe files while using Deep Linking and Lazy Loading Ionic 3?

南楼画角 提交于 2019-12-06 09:35:04
问题 I want to use a Provider, named as Translation.ts with a returnResult function in a Pipe named as TranslatePipe.ts . Translation.ts is @Injectable() export class TranslationProvider constructor() { } getResult(value) { returns something ; } } and TranslatePipe.ts is given as @Pipe({ name: 'translation', }) export class TranslationPipe implements PipeTransform { constructor(public translateService: TranslationProvider) { } transform(value: string, ...args) { return this.translateService

Isotope Gallery Error: Uncaught Error No layout mode packery line 8

房东的猫 提交于 2019-12-06 08:26:41
I am trying to use packery as a layout for my gallery. I am using fancybox with the isotope gallery. I don't see fancybox being the issue. I'm using isotope v2 and the latest packery download. Every single other layout works, even the ones not included in isotope js like fitRows and fitColumns. But with packery I get this error from isotope: Uncaught Error: No layout mode: packery isotope.pkgd.js line 8 Here is an example on codepen: http://codepen.io/anon/pen/QwXEvr JS: jQuery('.fancybox').fancybox({ openEffect: 'none', closeEffect: 'none' }); $('#testing').isotope({ 'layoutMode': 'packery';

Swing and lazy loading components

强颜欢笑 提交于 2019-12-06 08:15:45
问题 I have used the Eclipse plugin Visual Editor to construct Java Swing interfaces. As I'm not a big fan of the code WYSIWYG (UI) editors generate, I wanted to optimize it, when I noticed, that the editor implemented all elements using lazy loading like this: private JPanel getSomePanel () { if ( somePanel == null ) { somePanel = new JPanel(); // construct the panel } return somePanel; } I know that lazy loading is used to get better performance, when the objects in question are not used

Linq-To-Entities Include

偶尔善良 提交于 2019-12-06 08:03:03
问题 I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about eager and lazy loading. proxy.User.Include("Role").First(u => u.UserId == userId) This is supposed to load the User, along with any roles that user has. I have a problem, but I also have a question. It's just a simple model created to learn about L2E I was under the impression that this was designed to make things strongly type - so why do I have to write "Role"? It seems that if I changed the name of

How to implement Lazy loading with PostSharp?

谁说胖子不能爱 提交于 2019-12-06 08:02:07
问题 I would like to implement lazy loading on properties with PostSharp. To make it short, instead of writing SomeType _field = null; private SomeType Field { get { if (_field == null) { _field = LongOperation(); } return _field; } } I would like to write [LazyLoadAspect] private object Field { get { return LongOperation(); } } So, I identify that I need to emit some code in the class to generate the backing field, as well as inside the getter method in order to implement the test. With PostSharp