Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

jpa 2.0 - Execute @PostLoad _after_ eagerly fetching? -


using jpa2/hibernate, i've created entity has uni-directional mapping entity x (see below). inside a, have transient member "t" trying calculate using @postload method. calculation requires access assosiated xs:

@entity   public class {       // ...     @transient     int t;      @onetomany(orphanremoval = false, fetch = fetchtype.eager)       private list listofx;        @postload     public void calculatet() {         t = 0;         (x x : listofx)             t = t + x.somemethod();     } } 

however, when try load entity, "org.hibernate.lazyinitializationexception: illegal access loading collection" error.

 @ org.hibernate.collection.abstractpersistentcollection.initialize(abstractpersistentcollection.java:363)  @ org.hibernate.collection.abstractpersistentcollection.read(abstractpersistentcollection.java:108)  @ org.hibernate.collection.persistentbag.get(persistentbag.java:445)  @ java.util.collections$unmodifiablelist.get(collections.java:1154)  @ mypackage.a.calculatet(a.java:32)

looking @ hibernate's code (abstractpersistentcollection.java) while debugging, found that:

1) @postload method called before "listofx" member initialized
2) hibernate's code has explicit check prevent initialization of eagerly fetched collection during @postload:

 protected final void initialize(boolean writing) {   if (!initialized) {    if (initializing) {     throw new lazyinitializationexception("illegal access loading collection");    }    throwlazyinitializationexceptionifnotconnected();    session.initializecollection(this, writing);   }  } 

the way i'm thinking fix stop using @postload , move initialization code gett() accessor, adding synchronized block. however, want avoid that.

so, there way have eager fetching executed prior @postload being called? don't know of jpa facility that, i'm hoping there's don't know.

also, perhaps hibernate's proprietary api has control behaviour?

this might late, hibernate seems not support default jpa fetchtype option

@onetomany(orphanremoval = false, fetch = fetchtype.eager) 

you must use hibernate specific one:

@lazycollection(lazycollectionoption.false) 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -