Re: Wicket-Hibernate Related LazyInitializationException

2010-12-07 Thread nivs

Hi Dan,

I guess you were right with the thought process - 


nivs wrote:
 
  If you're still getting an LIE, there may be another association at play
 (a child of Phone?).
 

I noticed that when I navigated, it was only when the PhoneType which was an
entity (if not a collection on Phone) of Phone; when it was rendered threw
the exception.

public class Phone{

 String phoneNumber;
 PhoneType phoneType; //This one

}

So in the initial fetch, i got back 10 items and the List view rendered 5 of
them. The OpenSessionInViewFilter closed the session after I rendered 5
Phone items along with PhoneType. When i hit the next page button, since I
resorted to pulling the items of the Model(CPM), when it came to PhoneType
it threw the exception. The SetPhone was available since I had manually
iterated them in the DAO, so that was not a problem.

Apologies for not pondering deeper from your thoughts. So now I fetch items
for every pagination this opens a Session now I need to optimize it in terms
of hitting the back end.

Mm well...thank you one and all for your thoughts. I still have to get
around how I can add multiple phone numbers using this design.

Many thanks again
Niv



-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Wicket-Hibernate-Related-LazyInitializationException-tp3068534p3075946.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-07 Thread nivs

Eelco
Thanks again for your thoughts. Inline with this, I will look at optimizing
it and intend to switch to using LDM's.
Cheers
Niv
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Wicket-Hibernate-Related-LazyInitializationException-tp3068534p3076005.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-06 Thread Nivedan Nadaraj
Hi Eelco

Appreciate your time and thoughts. I guess I am going to have to look at LDM
approach, since from what yourself,James and Dan have already mentioned
that.
I noticed a pattern when it/the system throws the Exception I have to track
it closely and see if makes sense and then I guess have to refactor to use a
LDM.Still hazy to me.
Many thanks for the time and thoughts, much appreciated one and all.

Regards
Nivedan




On Sat, Dec 4, 2010 at 9:23 AM, Eelco Hillenius
eelco.hillen...@gmail.comwrote:

 Yep, or least something comparable. You need to re-attach those
 objects you're using to the session somehow, and often the easiest way
 to do that is to just load them again if they were previously
 detached. If you worry about the database being hit more than you
 want, you are probably prematurely optimizing, and if you still worry,
 you should fix this by through Hibernate's (or your own) second level
 cache, not by keeping your model objects inflated between requests.

 As a general rule, something we often repeat on this list, if you work
 with Hibernate managed objects in Wicket models, use detachable models
 (LDM is a common one) and make sure that these objects are 'deflated'
 between requests, meaning that e.g. you only keep references to their
 ids, or e.g. the algorithm to get the objects back again when needed.

 Eelco


 On Wed, Dec 1, 2010 at 10:13 PM, James Carman
 ja...@carmanconsulting.com wrote:
  Just make sure your form's model is a LDM too.
 
  On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com
 wrote:
  Hi All
 
  I am guessing this is more of a Hibernate thing/issue but if some one
 has
  encountered this and has a explanation that I can probably use from the
  Wicket front would be great.
 
  https://forum.hibernate.org/viewtopic.php?f=1t=1008473
 
 
  I have a LazyIntializationException when i page through some items. I
 use
  the PageableListView, the List item(s) are entities that are retrieved
 via
  an association Person.phones which is  a Set type.
  The funny thing is, the LIException is intermittent. I am also using
  OpenSessionInViewFilter. Any thoughts?
 
  By the way the this is the load() implemenation, I have set the Model
  Object's phoneList with a list of values fetched via the Service-DAO. I
  have used this with other entities without association and it works  but
 I
  guess is a different scenario(not associations)
 
  Model = new LoadableDetachableModelObject() {
 @Override
 protected Object load() {
 return containerForm.getModelObject().getPhoneList();
 }
 };
  }
 
  If someone has any thoughts would appreiciate hearing from you.
 
 
  Cheers
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Wicket-Hibernate Related LazyInitializationException

2010-12-05 Thread Nivedan Nadaraj
H Vineet

Thanks for taking the time again to respond. I appreciate every single
moment you have sent.

The reason why I add the Phone Number to a list is that, I only want to save
those numbers when the user hits the Save Button for the Person as a whole.
Lets say a Person X is looked up and loaded into a detail panel/page. As
part of his details I display a list of phone numbers he is linked with.
When the user hits Add new Phone
as part of the person's detail panel, I render a Phone detail panel (via
Ajax) yes, and then when user finishes describing the phone number details
hits the Done button.

OnDone - I simply add it to the List of existing phone numbers which is on
the Value Object that is linked to the CPM's Model. When the user finally
saves the Person along with the person the phone number's are persisted.
Now in relation to James Carman's thoughts, yes I have maintained the Phone
Numbers in a separate list and then copy them across to the Persistent Set
before I do the Save/Update.

The association on the Person entity has a SetPhone phones and by
Persisting the parent (Person) the encompassing Phones collection can be
saved/updated.Hope this is clear with #1 and #2. I cannot save the Phone by
itself because it needs a Person object to be persisted.(during a New
Person/Phone scenario for example)

You are right about using Ajax, so after the Save of the Person, I re-fetch
the Person again from backend and re-rendered the Subject and his Phone
Numbers List.

Certainly it is something how I have done but wanted to give a clearer
picture.

Thanks to every one for their time and attempt to help.
Cheers
niv


On Fri, Dec 3, 2010 at 5:35 PM, vineet semwal vineetsemwal1...@gmail.comwrote:

 afaik problem is you are doing form.getmodelobject(),that form could be
 ajax
 submitted and so you are trying to initialize associate
 collection in different session..

 i don't understand your 1. and 2.
 why are you adding to list when user has not clicked on save ?

 i think adding a new phone number or entry should itself means a new entry
 is persisted and user is shown the new list..


 On Fri, Dec 3, 2010 at 2:29 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Hi
  Yeah so at present, what I do is when the user
 
  1. Adds a new phone number, I add this to the existing list of
 phoneNumbers
  in the UI but yet to be persisted
  2. User now clicks Save - This saves the Main object ie a Person and
 since
  the new phone number is added to the collection while I save Person the
  enclosed associations (phones) also gets persisted
  3. I now, get the saved Person from backend and re-render the Person
  Information and the list of Phones(including the new one I added)
  4. All fine so far
  5. Now when i navigate /intermittently it breaks.
 
  This is response to your  i think better way would be persisting a
 user's
  new entry  and then showing
  him the actual list which is a reflection of your database..
 
  Cheers for the thoughts
  Niv
 
 
  On Fri, Dec 3, 2010 at 3:48 PM, vineet semwal 
 vineetsemwal1...@gmail.com
  wrote:
 
   afaik,if your collection is lazy ,you will be able to initialize it in
  the
   same session ..
   if you are trying to initialize it in a new/different session you will
  not
   be able to initialize it..
   what i did was making sure that you have a associate collection which
 is
  in
   the same session..
   i think better way would be persisting a user's new entry  and then
  showing
   him the actual list which is a reflection of your database..
  
  
   On Fri, Dec 3, 2010 at 12:50 PM, Nivedan Nadaraj 
 shravann...@gmail.com
   wrote:
  
Vineet
I have not tried that. In this scenario, it will overwrite the
 phone's
   the
user may have added to a list on the UI and is yet to be persisted.
 If
   you
know what I mean.
   
1, Initial fetch of Subject along with his phones ( 5 items)
2. User adds a new phone number to the subject ( 5 + 1 (yet to be
persisted)
3. If user navigates and the load() gets a list of Phones for the
  subject
it
will overwrite the ones user has added.
   
Not sure if that made sense, thanks for your thoughts
Will ping back
Niv
   
   
On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal 
   vineetsemwal1...@gmail.com
wrote:
   
 do you see the exception when you try this?
  @Override
   protected Object load() {
  // return
 containerForm.getModelObject().getPhoneList();
 return service.getRequiredObject(*).getPhoneList(); //or any thing
  like
it
 ..

   }

 On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj 
   shravann...@gmail.com
 wrote:

  Hi James
 
  Thanks for the time. I use the CPM for the whole use case.
 Mmm..is
   LDM
  mandatory for such a use case? Am open for thoughts just want the
   best
 way
  to implement it.
  Can you explain a bit further what your thought was 

Re: Wicket-Hibernate Related LazyInitializationException

2010-12-05 Thread Nivedan Nadaraj
Hi james,

Yes from the DAO after i get the person and his SetPhone I map them into a
ArrayList and is set into a Value Object that is returned to the
client/caller.
On the front end I use this List to render and then update this list based
on user action. When user wants to Save/Update, i map them back into the
hibernate entity Person's SetPhone
and do the Save/Update.

Thanks again for the time.
Niv

On Fri, Dec 3, 2010 at 7:53 PM, James Carman ja...@carmanconsulting.comwrote:

 Why not read the phones into a different list that you edit and
 when you're done, you update the entity.

 On Fri, Dec 3, 2010 at 2:20 AM, Nivedan Nadaraj shravann...@gmail.com
 wrote:
  Vineet
  I have not tried that. In this scenario, it will overwrite the phone's
 the
  user may have added to a list on the UI and is yet to be persisted. If
 you
  know what I mean.
 
  1, Initial fetch of Subject along with his phones ( 5 items)
  2. User adds a new phone number to the subject ( 5 + 1 (yet to be
 persisted)
  3. If user navigates and the load() gets a list of Phones for the subject
 it
  will overwrite the ones user has added.
 
  Not sure if that made sense, thanks for your thoughts
  Will ping back
  Niv
 
 
  On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal 
 vineetsemwal1...@gmail.comwrote:
 
  do you see the exception when you try this?
   @Override
protected Object load() {
   // return containerForm.getModelObject().getPhoneList();
  return service.getRequiredObject(*).getPhoneList(); //or any thing like
 it
  ..
 
}
 
  On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj shravann...@gmail.com
  wrote:
 
   Hi James
  
   Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
   mandatory for such a use case? Am open for thoughts just want the best
  way
   to implement it.
   Can you explain a bit further what your thought was please?
  
   Thank you
   Regards
  
  
  
  
   On Thu, Dec 2, 2010 at 2:13 PM, James Carman 
 ja...@carmanconsulting.com
   wrote:
  
Just make sure your form's model is a LDM too.
   
On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
  shravann...@gmail.com
wrote:
 Hi All

 I am guessing this is more of a Hibernate thing/issue but if some
 one
   has
 encountered this and has a explanation that I can probably use
 from
  the
 Wicket front would be great.

 https://forum.hibernate.org/viewtopic.php?f=1t=1008473


 I have a LazyIntializationException when i page through some
 items. I
   use
 the PageableListView, the List item(s) are entities that are
  retrieved
via
 an association Person.phones which is  a Set type.
 The funny thing is, the LIException is intermittent. I am also
 using
 OpenSessionInViewFilter. Any thoughts?

 By the way the this is the load() implemenation, I have set the
 Model
 Object's phoneList with a list of values fetched via the
  Service-DAO.
   I
 have used this with other entities without association and it
 works
but
I
 guess is a different scenario(not associations)

 Model = new LoadableDetachableModelObject() {
@Override
protected Object load() {
return
 containerForm.getModelObject().getPhoneList();
}
};
 }

 If someone has any thoughts would appreiciate hearing from you.


 Cheers

   
   
 -
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
   
   
  
 
 
 
  --
  regards,
  Vineet Semwal
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Wicket-Hibernate Related LazyInitializationException

2010-12-05 Thread Nivedan Nadaraj
Hi Eelco

Appreciate your time and thoughts. I guess I am going to look at LDM
approach, since from what yourself,James and Dan have already mentioned
that.
Hmm...well guess you guys have pointed me the required stuff to work on will
get back with more details hopefully with the solution.

Many thanks
Niv



On Sat, Dec 4, 2010 at 9:23 AM, Eelco Hillenius
eelco.hillen...@gmail.comwrote:

 Yep, or least something comparable. You need to re-attach those
 objects you're using to the session somehow, and often the easiest way
 to do that is to just load them again if they were previously
 detached. If you worry about the database being hit more than you
 want, you are probably prematurely optimizing, and if you still worry,
 you should fix this by through Hibernate's (or your own) second level
 cache, not by keeping your model objects inflated between requests.

 As a general rule, something we often repeat on this list, if you work
 with Hibernate managed objects in Wicket models, use detachable models
 (LDM is a common one) and make sure that these objects are 'deflated'
 between requests, meaning that e.g. you only keep references to their
 ids, or e.g. the algorithm to get the objects back again when needed.

 Eelco


 On Wed, Dec 1, 2010 at 10:13 PM, James Carman
 ja...@carmanconsulting.com wrote:
  Just make sure your form's model is a LDM too.
 
  On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com
 wrote:
  Hi All
 
  I am guessing this is more of a Hibernate thing/issue but if some one
 has
  encountered this and has a explanation that I can probably use from the
  Wicket front would be great.
 
  https://forum.hibernate.org/viewtopic.php?f=1t=1008473
 
 
  I have a LazyIntializationException when i page through some items. I
 use
  the PageableListView, the List item(s) are entities that are retrieved
 via
  an association Person.phones which is  a Set type.
  The funny thing is, the LIException is intermittent. I am also using
  OpenSessionInViewFilter. Any thoughts?
 
  By the way the this is the load() implemenation, I have set the Model
  Object's phoneList with a list of values fetched via the Service-DAO. I
  have used this with other entities without association and it works  but
 I
  guess is a different scenario(not associations)
 
  Model = new LoadableDetachableModelObject() {
 @Override
 protected Object load() {
 return containerForm.getModelObject().getPhoneList();
 }
 };
  }
 
  If someone has any thoughts would appreiciate hearing from you.
 
 
  Cheers
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Wicket-Hibernate Related LazyInitializationException

2010-12-03 Thread Nivedan Nadaraj
Hi
Yeah so at present, what I do is when the user

1. Adds a new phone number, I add this to the existing list of phoneNumbers
in the UI but yet to be persisted
2. User now clicks Save - This saves the Main object ie a Person and since
the new phone number is added to the collection while I save Person the
enclosed associations (phones) also gets persisted
3. I now, get the saved Person from backend and re-render the Person
Information and the list of Phones(including the new one I added)
4. All fine so far
5. Now when i navigate /intermittently it breaks.

This is response to your  i think better way would be persisting a user's
new entry  and then showing
him the actual list which is a reflection of your database..

Cheers for the thoughts
Niv


On Fri, Dec 3, 2010 at 3:48 PM, vineet semwal vineetsemwal1...@gmail.comwrote:

 afaik,if your collection is lazy ,you will be able to initialize it in the
 same session ..
 if you are trying to initialize it in a new/different session you will not
 be able to initialize it..
 what i did was making sure that you have a associate collection which is in
 the same session..
 i think better way would be persisting a user's new entry  and then showing
 him the actual list which is a reflection of your database..


 On Fri, Dec 3, 2010 at 12:50 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Vineet
  I have not tried that. In this scenario, it will overwrite the phone's
 the
  user may have added to a list on the UI and is yet to be persisted. If
 you
  know what I mean.
 
  1, Initial fetch of Subject along with his phones ( 5 items)
  2. User adds a new phone number to the subject ( 5 + 1 (yet to be
  persisted)
  3. If user navigates and the load() gets a list of Phones for the subject
  it
  will overwrite the ones user has added.
 
  Not sure if that made sense, thanks for your thoughts
  Will ping back
  Niv
 
 
  On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal 
 vineetsemwal1...@gmail.com
  wrote:
 
   do you see the exception when you try this?
@Override
 protected Object load() {
// return containerForm.getModelObject().getPhoneList();
   return service.getRequiredObject(*).getPhoneList(); //or any thing like
  it
   ..
  
 }
  
   On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj 
 shravann...@gmail.com
   wrote:
  
Hi James
   
Thanks for the time. I use the CPM for the whole use case. Mmm..is
 LDM
mandatory for such a use case? Am open for thoughts just want the
 best
   way
to implement it.
Can you explain a bit further what your thought was please?
   
Thank you
Regards
   
   
   
   
On Thu, Dec 2, 2010 at 2:13 PM, James Carman 
  ja...@carmanconsulting.com
wrote:
   
 Just make sure your form's model is a LDM too.

 On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
   shravann...@gmail.com
 wrote:
  Hi All
 
  I am guessing this is more of a Hibernate thing/issue but if some
  one
has
  encountered this and has a explanation that I can probably use
 from
   the
  Wicket front would be great.
 
  https://forum.hibernate.org/viewtopic.php?f=1t=1008473
 
 
  I have a LazyIntializationException when i page through some
 items.
  I
use
  the PageableListView, the List item(s) are entities that are
   retrieved
 via
  an association Person.phones which is  a Set type.
  The funny thing is, the LIException is intermittent. I am also
  using
  OpenSessionInViewFilter. Any thoughts?
 
  By the way the this is the load() implemenation, I have set the
  Model
  Object's phoneList with a list of values fetched via the
   Service-DAO.
I
  have used this with other entities without association and it
 works
 but
 I
  guess is a different scenario(not associations)
 
  Model = new LoadableDetachableModelObject() {
 @Override
 protected Object load() {
 return
  containerForm.getModelObject().getPhoneList();
 }
 };
  }
 
  If someone has any thoughts would appreiciate hearing from you.
 
 
  Cheers
 


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org


   
  
  
  
   --
   regards,
   Vineet Semwal
  
 



 --
 regards,
 Vineet Semwal



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-03 Thread Nivedan Nadaraj
Dan,

Thanks mate. I am yet to digest all that. I am going to get back to you and
see if it all helped.

Thank you for the time
Cheers
niv

On Fri, Dec 3, 2010 at 1:06 AM, Dan Retzlaff dretzl...@gmail.com wrote:

 Yes, copying entities from the entity's association collection into another
 collection will initialize the collection. If you're still getting an LIE,
 there may be another association at play (a child of Phone?).

 Note that I don't fully endorse the session reattachment aspect I posted.
 Not only is weaving those Hibernate classes a little tricky and a lot of
 hacky, it can cause undesirable amounts of entities to be added into the
 session. James' suggestion of putting the collection behind a Wicket model
 is more elegant. To this end, you might develop a utility which, given a
 list of Persons, returns an IModelListPerson while storing only their
 IDs in the session. In the following code, BasicDao.getIdentifier() and
 BasicDao.get() simply map to Hibernate Session methods of the same name for
 entity class T.

 public static T IModelListT createListModelFromObjects(final
 BasicDaoT dao, ListT objectList) {
 final ListSerializable idList = new
 ArrayListSerializable(objectList.size());
 for (T object : objectList) {
 idList.add(dao.getIdentifier(object));
 }
  return new LoadableDetachableModelListT(objectList) {
 @Override
 protected ListT load() {
 return loadList(dao, idList);
 }
 };
 }

 private static T ListT loadList(BasicDaoT dao, List? extends
 Serializable idList) {
 ListT loadList = new ArrayListT(idList.size());
 for (Serializable id : idList) {
 loadList.add(dao.get(id));
 }
 return loadList;
 }


 On Wed, Dec 1, 2010 at 10:26 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Hi Dan,
 
  Thanks for your time most appreciated.
 
  1. Option 1 as you may agree, not always is a good thing to do so I would
  drop that.
 
  2. Option 2 - I have tried this in the following manner.
 
  As part of the look up for the Subjects via the DAO, I iterate through
 the
  list of Person.Phones collection and assign them into a
 CollectionPhones
  and set it into a value Object with has a List. This is because i cannot
  use
  the Set in the PageableListView. In doing so, I have forced the entities
 in
  the collection/proxy to be intialised isn't it? Looks like even with this
  it
  beats me.
 
  3. Option 3 - I have to read up more on how I can use this code/or
  something
  similar, we use Spring for DI.
 
  Further, each time I want to view a Person detail, I do a second look up
  when the user clicks from a list of Persons. I send issue a lookup into
 the
  DAO to get the Person's details afresh(the exact same method I used to
 list
  all Subjects in the first place), so this again would have refreshed the
  Phones collection on the Person in context.
 
  I will try to track it down I guess it has to do with session anyway. I
  also
  use the CPM to hold the Model for the whole page. Not a LDM.
 
  Thanks again for the time
  Cheers
  Niv
 
 
  On Thu, Dec 2, 2010 at 1:47 PM, Dan Retzlaff dretzl...@gmail.com
 wrote:
 
   Hi Nivedan,
  
   Even though the subsequent requests have a Session open, the entities
  with
   the uninitialized collections don't know about it. I'm sure if you
 track
  it
   down, you can explain the intermittent behavior by prior access to
 the
   collection when the original session is open.
  
   I'd say you can either (1) configure Hibernate to load the collections
 to
   load unlazily, (2) manually access the collections to force them to
   initialize in the specific cases you're encountering LIEs, or (3)
 employ
   some kind of AOP hack to reinject the new session right before the
   collection is accessed. They're all kind of ugly, and I've never heard
 of
   anyone else doing the last, but it's been working well for my team.
  
   For your reference, here is the AspectJ aspect I wrote. (We use Guice
 for
   dependency injection.)
  
   /**
* Reattaches entities whose lazy collections are about to be
 initialized
* p
* Can we keep track of all lazy relationships that get initialized,
 and
* uninitialize them at the end of the request? This would prevent
   referenced
* entities from being serialized and replicated (unless separate
   references
* were created to them).
*
* @author dan
*/
   @Aspect
   public class ReattachAspect {
   private static final Logger LOG =
 Logger.getLogger(ReattachAspect.class);
  
   private ProviderSession sessionProvider;
  
   @Before(call(public final void
   org.hibernate.proxy.AbstractLazyInitializer.initialize()) 
   target(initializer))
   public void reattachLazyInitializer(LazyInitializer initializer) {
   if (initializer.getSession() == null  sessionProvider != null) {
   if (LOG.isDebugEnabled()) {
   LOG.debug(reattaching session to lazy initializer for  +
   initializer.getEntityName());
   }
   Session session = sessionProvider.get();
   

Re: Wicket-Hibernate Related LazyInitializationException

2010-12-03 Thread vineet semwal
afaik problem is you are doing form.getmodelobject(),that form could be ajax
submitted and so you are trying to initialize associate
collection in different session..

i don't understand your 1. and 2.
why are you adding to list when user has not clicked on save ?

i think adding a new phone number or entry should itself means a new entry
is persisted and user is shown the new list..


On Fri, Dec 3, 2010 at 2:29 PM, Nivedan Nadaraj shravann...@gmail.comwrote:

 Hi
 Yeah so at present, what I do is when the user

 1. Adds a new phone number, I add this to the existing list of phoneNumbers
 in the UI but yet to be persisted
 2. User now clicks Save - This saves the Main object ie a Person and since
 the new phone number is added to the collection while I save Person the
 enclosed associations (phones) also gets persisted
 3. I now, get the saved Person from backend and re-render the Person
 Information and the list of Phones(including the new one I added)
 4. All fine so far
 5. Now when i navigate /intermittently it breaks.

 This is response to your  i think better way would be persisting a user's
 new entry  and then showing
 him the actual list which is a reflection of your database..

 Cheers for the thoughts
 Niv


 On Fri, Dec 3, 2010 at 3:48 PM, vineet semwal vineetsemwal1...@gmail.com
 wrote:

  afaik,if your collection is lazy ,you will be able to initialize it in
 the
  same session ..
  if you are trying to initialize it in a new/different session you will
 not
  be able to initialize it..
  what i did was making sure that you have a associate collection which is
 in
  the same session..
  i think better way would be persisting a user's new entry  and then
 showing
  him the actual list which is a reflection of your database..
 
 
  On Fri, Dec 3, 2010 at 12:50 PM, Nivedan Nadaraj shravann...@gmail.com
  wrote:
 
   Vineet
   I have not tried that. In this scenario, it will overwrite the phone's
  the
   user may have added to a list on the UI and is yet to be persisted. If
  you
   know what I mean.
  
   1, Initial fetch of Subject along with his phones ( 5 items)
   2. User adds a new phone number to the subject ( 5 + 1 (yet to be
   persisted)
   3. If user navigates and the load() gets a list of Phones for the
 subject
   it
   will overwrite the ones user has added.
  
   Not sure if that made sense, thanks for your thoughts
   Will ping back
   Niv
  
  
   On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal 
  vineetsemwal1...@gmail.com
   wrote:
  
do you see the exception when you try this?
 @Override
  protected Object load() {
 // return containerForm.getModelObject().getPhoneList();
return service.getRequiredObject(*).getPhoneList(); //or any thing
 like
   it
..
   
  }
   
On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj 
  shravann...@gmail.com
wrote:
   
 Hi James

 Thanks for the time. I use the CPM for the whole use case. Mmm..is
  LDM
 mandatory for such a use case? Am open for thoughts just want the
  best
way
 to implement it.
 Can you explain a bit further what your thought was please?

 Thank you
 Regards




 On Thu, Dec 2, 2010 at 2:13 PM, James Carman 
   ja...@carmanconsulting.com
 wrote:

  Just make sure your form's model is a LDM too.
 
  On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
shravann...@gmail.com
  wrote:
   Hi All
  
   I am guessing this is more of a Hibernate thing/issue but if
 some
   one
 has
   encountered this and has a explanation that I can probably use
  from
the
   Wicket front would be great.
  
   https://forum.hibernate.org/viewtopic.php?f=1t=1008473
  
  
   I have a LazyIntializationException when i page through some
  items.
   I
 use
   the PageableListView, the List item(s) are entities that are
retrieved
  via
   an association Person.phones which is  a Set type.
   The funny thing is, the LIException is intermittent. I am also
   using
   OpenSessionInViewFilter. Any thoughts?
  
   By the way the this is the load() implemenation, I have set the
   Model
   Object's phoneList with a list of values fetched via the
Service-DAO.
 I
   have used this with other entities without association and it
  works
  but
  I
   guess is a different scenario(not associations)
  
   Model = new LoadableDetachableModelObject() {
  @Override
  protected Object load() {
  return
   containerForm.getModelObject().getPhoneList();
  }
  };
   }
  
   If someone has any thoughts would appreiciate hearing from you.
  
  
   Cheers
  
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  

Re: Wicket-Hibernate Related LazyInitializationException

2010-12-03 Thread James Carman
Why not read the phones into a different list that you edit and
when you're done, you update the entity.

On Fri, Dec 3, 2010 at 2:20 AM, Nivedan Nadaraj shravann...@gmail.com wrote:
 Vineet
 I have not tried that. In this scenario, it will overwrite the phone's the
 user may have added to a list on the UI and is yet to be persisted. If you
 know what I mean.

 1, Initial fetch of Subject along with his phones ( 5 items)
 2. User adds a new phone number to the subject ( 5 + 1 (yet to be persisted)
 3. If user navigates and the load() gets a list of Phones for the subject it
 will overwrite the ones user has added.

 Not sure if that made sense, thanks for your thoughts
 Will ping back
 Niv


 On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal 
 vineetsemwal1...@gmail.comwrote:

 do you see the exception when you try this?
         �...@override
           protected Object load() {
              // return containerForm.getModelObject().getPhoneList();
 return service.getRequiredObject(*).getPhoneList(); //or any thing like it
 ..

           }

 On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Hi James
 
  Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
  mandatory for such a use case? Am open for thoughts just want the best
 way
  to implement it.
  Can you explain a bit further what your thought was please?
 
  Thank you
  Regards
 
 
 
 
  On Thu, Dec 2, 2010 at 2:13 PM, James Carman ja...@carmanconsulting.com
  wrote:
 
   Just make sure your form's model is a LDM too.
  
   On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
 shravann...@gmail.com
   wrote:
Hi All
   
I am guessing this is more of a Hibernate thing/issue but if some one
  has
encountered this and has a explanation that I can probably use from
 the
Wicket front would be great.
   
https://forum.hibernate.org/viewtopic.php?f=1t=1008473
   
   
I have a LazyIntializationException when i page through some items. I
  use
the PageableListView, the List item(s) are entities that are
 retrieved
   via
an association Person.phones which is  a Set type.
The funny thing is, the LIException is intermittent. I am also using
OpenSessionInViewFilter. Any thoughts?
   
By the way the this is the load() implemenation, I have set the Model
Object's phoneList with a list of values fetched via the
 Service-DAO.
  I
have used this with other entities without association and it works
   but
   I
guess is a different scenario(not associations)
   
Model = new LoadableDetachableModelObject() {
  �...@override
           protected Object load() {
               return containerForm.getModelObject().getPhoneList();
           }
       };
}
   
If someone has any thoughts would appreiciate hearing from you.
   
   
Cheers
   
  
   -
   To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
   For additional commands, e-mail: users-h...@wicket.apache.org
  
  
 



 --
 regards,
 Vineet Semwal



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-03 Thread Eelco Hillenius
Yep, or least something comparable. You need to re-attach those
objects you're using to the session somehow, and often the easiest way
to do that is to just load them again if they were previously
detached. If you worry about the database being hit more than you
want, you are probably prematurely optimizing, and if you still worry,
you should fix this by through Hibernate's (or your own) second level
cache, not by keeping your model objects inflated between requests.

As a general rule, something we often repeat on this list, if you work
with Hibernate managed objects in Wicket models, use detachable models
(LDM is a common one) and make sure that these objects are 'deflated'
between requests, meaning that e.g. you only keep references to their
ids, or e.g. the algorithm to get the objects back again when needed.

Eelco


On Wed, Dec 1, 2010 at 10:13 PM, James Carman
ja...@carmanconsulting.com wrote:
 Just make sure your form's model is a LDM too.

 On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com 
 wrote:
 Hi All

 I am guessing this is more of a Hibernate thing/issue but if some one has
 encountered this and has a explanation that I can probably use from the
 Wicket front would be great.

 https://forum.hibernate.org/viewtopic.php?f=1t=1008473


 I have a LazyIntializationException when i page through some items. I use
 the PageableListView, the List item(s) are entities that are retrieved via
 an association Person.phones which is  a Set type.
 The funny thing is, the LIException is intermittent. I am also using
 OpenSessionInViewFilter. Any thoughts?

 By the way the this is the load() implemenation, I have set the Model
 Object's phoneList with a list of values fetched via the Service-DAO. I
 have used this with other entities without association and it works  but I
 guess is a different scenario(not associations)

 Model = new LoadableDetachableModelObject() {
   �...@override
            protected Object load() {
                return containerForm.getModelObject().getPhoneList();
            }
        };
 }

 If someone has any thoughts would appreiciate hearing from you.


 Cheers


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-02 Thread vineet semwal
do you see the exception when you try this?
 @Override
   protected Object load() {
  // return containerForm.getModelObject().getPhoneList();
return service.getRequiredObject(*).getPhoneList(); //or any thing like it
..

   }

On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj shravann...@gmail.comwrote:

 Hi James

 Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
 mandatory for such a use case? Am open for thoughts just want the best way
 to implement it.
 Can you explain a bit further what your thought was please?

 Thank you
 Regards




 On Thu, Dec 2, 2010 at 2:13 PM, James Carman ja...@carmanconsulting.com
 wrote:

  Just make sure your form's model is a LDM too.
 
  On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com
  wrote:
   Hi All
  
   I am guessing this is more of a Hibernate thing/issue but if some one
 has
   encountered this and has a explanation that I can probably use from the
   Wicket front would be great.
  
   https://forum.hibernate.org/viewtopic.php?f=1t=1008473
  
  
   I have a LazyIntializationException when i page through some items. I
 use
   the PageableListView, the List item(s) are entities that are retrieved
  via
   an association Person.phones which is  a Set type.
   The funny thing is, the LIException is intermittent. I am also using
   OpenSessionInViewFilter. Any thoughts?
  
   By the way the this is the load() implemenation, I have set the Model
   Object's phoneList with a list of values fetched via the Service-DAO.
 I
   have used this with other entities without association and it works
  but
  I
   guess is a different scenario(not associations)
  
   Model = new LoadableDetachableModelObject() {
  @Override
  protected Object load() {
  return containerForm.getModelObject().getPhoneList();
  }
  };
   }
  
   If someone has any thoughts would appreiciate hearing from you.
  
  
   Cheers
  
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 




-- 
regards,
Vineet Semwal


Re: Wicket-Hibernate Related LazyInitializationException

2010-12-02 Thread Dan Retzlaff
Yes, copying entities from the entity's association collection into another
collection will initialize the collection. If you're still getting an LIE,
there may be another association at play (a child of Phone?).

Note that I don't fully endorse the session reattachment aspect I posted.
Not only is weaving those Hibernate classes a little tricky and a lot of
hacky, it can cause undesirable amounts of entities to be added into the
session. James' suggestion of putting the collection behind a Wicket model
is more elegant. To this end, you might develop a utility which, given a
list of Persons, returns an IModelListPerson while storing only their
IDs in the session. In the following code, BasicDao.getIdentifier() and
BasicDao.get() simply map to Hibernate Session methods of the same name for
entity class T.

public static T IModelListT createListModelFromObjects(final
BasicDaoT dao, ListT objectList) {
final ListSerializable idList = new
ArrayListSerializable(objectList.size());
for (T object : objectList) {
idList.add(dao.getIdentifier(object));
}
 return new LoadableDetachableModelListT(objectList) {
@Override
protected ListT load() {
return loadList(dao, idList);
}
};
}

private static T ListT loadList(BasicDaoT dao, List? extends
Serializable idList) {
ListT loadList = new ArrayListT(idList.size());
for (Serializable id : idList) {
loadList.add(dao.get(id));
}
return loadList;
}


On Wed, Dec 1, 2010 at 10:26 PM, Nivedan Nadaraj shravann...@gmail.comwrote:

 Hi Dan,

 Thanks for your time most appreciated.

 1. Option 1 as you may agree, not always is a good thing to do so I would
 drop that.

 2. Option 2 - I have tried this in the following manner.

 As part of the look up for the Subjects via the DAO, I iterate through the
 list of Person.Phones collection and assign them into a CollectionPhones
 and set it into a value Object with has a List. This is because i cannot
 use
 the Set in the PageableListView. In doing so, I have forced the entities in
 the collection/proxy to be intialised isn't it? Looks like even with this
 it
 beats me.

 3. Option 3 - I have to read up more on how I can use this code/or
 something
 similar, we use Spring for DI.

 Further, each time I want to view a Person detail, I do a second look up
 when the user clicks from a list of Persons. I send issue a lookup into the
 DAO to get the Person's details afresh(the exact same method I used to list
 all Subjects in the first place), so this again would have refreshed the
 Phones collection on the Person in context.

 I will try to track it down I guess it has to do with session anyway. I
 also
 use the CPM to hold the Model for the whole page. Not a LDM.

 Thanks again for the time
 Cheers
 Niv


 On Thu, Dec 2, 2010 at 1:47 PM, Dan Retzlaff dretzl...@gmail.com wrote:

  Hi Nivedan,
 
  Even though the subsequent requests have a Session open, the entities
 with
  the uninitialized collections don't know about it. I'm sure if you track
 it
  down, you can explain the intermittent behavior by prior access to the
  collection when the original session is open.
 
  I'd say you can either (1) configure Hibernate to load the collections to
  load unlazily, (2) manually access the collections to force them to
  initialize in the specific cases you're encountering LIEs, or (3) employ
  some kind of AOP hack to reinject the new session right before the
  collection is accessed. They're all kind of ugly, and I've never heard of
  anyone else doing the last, but it's been working well for my team.
 
  For your reference, here is the AspectJ aspect I wrote. (We use Guice for
  dependency injection.)
 
  /**
   * Reattaches entities whose lazy collections are about to be initialized
   * p
   * Can we keep track of all lazy relationships that get initialized, and
   * uninitialize them at the end of the request? This would prevent
  referenced
   * entities from being serialized and replicated (unless separate
  references
   * were created to them).
   *
   * @author dan
   */
  @Aspect
  public class ReattachAspect {
  private static final Logger LOG = Logger.getLogger(ReattachAspect.class);
 
  private ProviderSession sessionProvider;
 
  @Before(call(public final void
  org.hibernate.proxy.AbstractLazyInitializer.initialize()) 
  target(initializer))
  public void reattachLazyInitializer(LazyInitializer initializer) {
  if (initializer.getSession() == null  sessionProvider != null) {
  if (LOG.isDebugEnabled()) {
  LOG.debug(reattaching session to lazy initializer for  +
  initializer.getEntityName());
  }
  Session session = sessionProvider.get();
  initializer.setSession((SessionImplementor) session);
  }
  }
 
  @Before(call(private void
  org.hibernate.collection.AbstractPersistentCollection
  + .throwLazyInitializationExceptionIfNotConnected()) 
  target(collection))
  public void reattachPersistentCollection(PersistentCollection collection)
 {
  SessionImplementor session = ((AbstractPersistentCollection)
  

Re: Wicket-Hibernate Related LazyInitializationException

2010-12-02 Thread Nivedan Nadaraj
Vineet
I have not tried that. In this scenario, it will overwrite the phone's the
user may have added to a list on the UI and is yet to be persisted. If you
know what I mean.

1, Initial fetch of Subject along with his phones ( 5 items)
2. User adds a new phone number to the subject ( 5 + 1 (yet to be persisted)
3. If user navigates and the load() gets a list of Phones for the subject it
will overwrite the ones user has added.

Not sure if that made sense, thanks for your thoughts
Will ping back
Niv


On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal vineetsemwal1...@gmail.comwrote:

 do you see the exception when you try this?
  @Override
   protected Object load() {
  // return containerForm.getModelObject().getPhoneList();
 return service.getRequiredObject(*).getPhoneList(); //or any thing like it
 ..

   }

 On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Hi James
 
  Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
  mandatory for such a use case? Am open for thoughts just want the best
 way
  to implement it.
  Can you explain a bit further what your thought was please?
 
  Thank you
  Regards
 
 
 
 
  On Thu, Dec 2, 2010 at 2:13 PM, James Carman ja...@carmanconsulting.com
  wrote:
 
   Just make sure your form's model is a LDM too.
  
   On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
 shravann...@gmail.com
   wrote:
Hi All
   
I am guessing this is more of a Hibernate thing/issue but if some one
  has
encountered this and has a explanation that I can probably use from
 the
Wicket front would be great.
   
https://forum.hibernate.org/viewtopic.php?f=1t=1008473
   
   
I have a LazyIntializationException when i page through some items. I
  use
the PageableListView, the List item(s) are entities that are
 retrieved
   via
an association Person.phones which is  a Set type.
The funny thing is, the LIException is intermittent. I am also using
OpenSessionInViewFilter. Any thoughts?
   
By the way the this is the load() implemenation, I have set the Model
Object's phoneList with a list of values fetched via the
 Service-DAO.
  I
have used this with other entities without association and it works
   but
   I
guess is a different scenario(not associations)
   
Model = new LoadableDetachableModelObject() {
   @Override
   protected Object load() {
   return containerForm.getModelObject().getPhoneList();
   }
   };
}
   
If someone has any thoughts would appreiciate hearing from you.
   
   
Cheers
   
  
   -
   To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
   For additional commands, e-mail: users-h...@wicket.apache.org
  
  
 



 --
 regards,
 Vineet Semwal



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-02 Thread vineet semwal
afaik,if your collection is lazy ,you will be able to initialize it in the
same session ..
if you are trying to initialize it in a new/different session you will not
be able to initialize it..
what i did was making sure that you have a associate collection which is in
the same session..
i think better way would be persisting a user's new entry  and then showing
him the actual list which is a reflection of your database..


On Fri, Dec 3, 2010 at 12:50 PM, Nivedan Nadaraj shravann...@gmail.comwrote:

 Vineet
 I have not tried that. In this scenario, it will overwrite the phone's the
 user may have added to a list on the UI and is yet to be persisted. If you
 know what I mean.

 1, Initial fetch of Subject along with his phones ( 5 items)
 2. User adds a new phone number to the subject ( 5 + 1 (yet to be
 persisted)
 3. If user navigates and the load() gets a list of Phones for the subject
 it
 will overwrite the ones user has added.

 Not sure if that made sense, thanks for your thoughts
 Will ping back
 Niv


 On Thu, Dec 2, 2010 at 5:43 PM, vineet semwal vineetsemwal1...@gmail.com
 wrote:

  do you see the exception when you try this?
   @Override
protected Object load() {
   // return containerForm.getModelObject().getPhoneList();
  return service.getRequiredObject(*).getPhoneList(); //or any thing like
 it
  ..
 
}
 
  On Thu, Dec 2, 2010 at 12:12 PM, Nivedan Nadaraj shravann...@gmail.com
  wrote:
 
   Hi James
  
   Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
   mandatory for such a use case? Am open for thoughts just want the best
  way
   to implement it.
   Can you explain a bit further what your thought was please?
  
   Thank you
   Regards
  
  
  
  
   On Thu, Dec 2, 2010 at 2:13 PM, James Carman 
 ja...@carmanconsulting.com
   wrote:
  
Just make sure your form's model is a LDM too.
   
On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj 
  shravann...@gmail.com
wrote:
 Hi All

 I am guessing this is more of a Hibernate thing/issue but if some
 one
   has
 encountered this and has a explanation that I can probably use from
  the
 Wicket front would be great.

 https://forum.hibernate.org/viewtopic.php?f=1t=1008473


 I have a LazyIntializationException when i page through some items.
 I
   use
 the PageableListView, the List item(s) are entities that are
  retrieved
via
 an association Person.phones which is  a Set type.
 The funny thing is, the LIException is intermittent. I am also
 using
 OpenSessionInViewFilter. Any thoughts?

 By the way the this is the load() implemenation, I have set the
 Model
 Object's phoneList with a list of values fetched via the
  Service-DAO.
   I
 have used this with other entities without association and it works
but
I
 guess is a different scenario(not associations)

 Model = new LoadableDetachableModelObject() {
@Override
protected Object load() {
return
 containerForm.getModelObject().getPhoneList();
}
};
 }

 If someone has any thoughts would appreiciate hearing from you.


 Cheers

   
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
   
   
  
 
 
 
  --
  regards,
  Vineet Semwal
 




-- 
regards,
Vineet Semwal


Wicket-Hibernate Related LazyInitializationException

2010-12-01 Thread Nivedan Nadaraj
Hi All

I am guessing this is more of a Hibernate thing/issue but if some one has
encountered this and has a explanation that I can probably use from the
Wicket front would be great.

https://forum.hibernate.org/viewtopic.php?f=1t=1008473


I have a LazyIntializationException when i page through some items. I use
the PageableListView, the List item(s) are entities that are retrieved via
an association Person.phones which is  a Set type.
The funny thing is, the LIException is intermittent. I am also using
OpenSessionInViewFilter. Any thoughts?

By the way the this is the load() implemenation, I have set the Model
Object's phoneList with a list of values fetched via the Service-DAO. I
have used this with other entities without association and it works  but I
guess is a different scenario(not associations)

Model = new LoadableDetachableModelObject() {
@Override
protected Object load() {
return containerForm.getModelObject().getPhoneList();
}
};
}

If someone has any thoughts would appreiciate hearing from you.


Cheers


Re: Wicket-Hibernate Related LazyInitializationException

2010-12-01 Thread Dan Retzlaff
Hi Nivedan,

Even though the subsequent requests have a Session open, the entities with
the uninitialized collections don't know about it. I'm sure if you track it
down, you can explain the intermittent behavior by prior access to the
collection when the original session is open.

I'd say you can either (1) configure Hibernate to load the collections to
load unlazily, (2) manually access the collections to force them to
initialize in the specific cases you're encountering LIEs, or (3) employ
some kind of AOP hack to reinject the new session right before the
collection is accessed. They're all kind of ugly, and I've never heard of
anyone else doing the last, but it's been working well for my team.

For your reference, here is the AspectJ aspect I wrote. (We use Guice for
dependency injection.)

/**
 * Reattaches entities whose lazy collections are about to be initialized
 * p
 * Can we keep track of all lazy relationships that get initialized, and
 * uninitialize them at the end of the request? This would prevent
referenced
 * entities from being serialized and replicated (unless separate references
 * were created to them).
 *
 * @author dan
 */
@Aspect
public class ReattachAspect {
private static final Logger LOG = Logger.getLogger(ReattachAspect.class);

private ProviderSession sessionProvider;

@Before(call(public final void
org.hibernate.proxy.AbstractLazyInitializer.initialize()) 
target(initializer))
public void reattachLazyInitializer(LazyInitializer initializer) {
if (initializer.getSession() == null  sessionProvider != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(reattaching session to lazy initializer for  +
initializer.getEntityName());
}
Session session = sessionProvider.get();
initializer.setSession((SessionImplementor) session);
}
}

@Before(call(private void
org.hibernate.collection.AbstractPersistentCollection
+ .throwLazyInitializationExceptionIfNotConnected()) 
target(collection))
public void reattachPersistentCollection(PersistentCollection collection) {
SessionImplementor session = ((AbstractPersistentCollection)
collection).getSession();
if ((session == null || !session.isOpen())  sessionProvider != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(reattaching session to collection);
}

session = (SessionImplementor) sessionProvider.get();
CollectionPersister persister =
session.getFactory().getCollectionPersister(collection.getRole());

collection.setCurrentSession(session);
session.getPersistenceContext().addInitializedDetachedCollection(persister,
collection);
}
}

@Inject
public void setSessionProvider(ProviderSession sessionProvider) {
this.sessionProvider = sessionProvider;
}
}


On Wed, Dec 1, 2010 at 9:23 PM, Nivedan Nadaraj shravann...@gmail.comwrote:

 Hi All

 I am guessing this is more of a Hibernate thing/issue but if some one has
 encountered this and has a explanation that I can probably use from the
 Wicket front would be great.

 https://forum.hibernate.org/viewtopic.php?f=1t=1008473


 I have a LazyIntializationException when i page through some items. I use
 the PageableListView, the List item(s) are entities that are retrieved via
 an association Person.phones which is  a Set type.
 The funny thing is, the LIException is intermittent. I am also using
 OpenSessionInViewFilter. Any thoughts?

 By the way the this is the load() implemenation, I have set the Model
 Object's phoneList with a list of values fetched via the Service-DAO. I
 have used this with other entities without association and it works  but I
 guess is a different scenario(not associations)

 Model = new LoadableDetachableModelObject() {
@Override
protected Object load() {
return containerForm.getModelObject().getPhoneList();
}
};
 }

 If someone has any thoughts would appreiciate hearing from you.


 Cheers



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-01 Thread James Carman
Just make sure your form's model is a LDM too.

On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com wrote:
 Hi All

 I am guessing this is more of a Hibernate thing/issue but if some one has
 encountered this and has a explanation that I can probably use from the
 Wicket front would be great.

 https://forum.hibernate.org/viewtopic.php?f=1t=1008473


 I have a LazyIntializationException when i page through some items. I use
 the PageableListView, the List item(s) are entities that are retrieved via
 an association Person.phones which is  a Set type.
 The funny thing is, the LIException is intermittent. I am also using
 OpenSessionInViewFilter. Any thoughts?

 By the way the this is the load() implemenation, I have set the Model
 Object's phoneList with a list of values fetched via the Service-DAO. I
 have used this with other entities without association and it works  but I
 guess is a different scenario(not associations)

 Model = new LoadableDetachableModelObject() {
   �...@override
            protected Object load() {
                return containerForm.getModelObject().getPhoneList();
            }
        };
 }

 If someone has any thoughts would appreiciate hearing from you.


 Cheers


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket-Hibernate Related LazyInitializationException

2010-12-01 Thread Nivedan Nadaraj
Hi Dan,

Thanks for your time most appreciated.

1. Option 1 as you may agree, not always is a good thing to do so I would
drop that.

2. Option 2 - I have tried this in the following manner.

As part of the look up for the Subjects via the DAO, I iterate through the
list of Person.Phones collection and assign them into a CollectionPhones
and set it into a value Object with has a List. This is because i cannot use
the Set in the PageableListView. In doing so, I have forced the entities in
the collection/proxy to be intialised isn't it? Looks like even with this it
beats me.

3. Option 3 - I have to read up more on how I can use this code/or something
similar, we use Spring for DI.

Further, each time I want to view a Person detail, I do a second look up
when the user clicks from a list of Persons. I send issue a lookup into the
DAO to get the Person's details afresh(the exact same method I used to list
all Subjects in the first place), so this again would have refreshed the
Phones collection on the Person in context.

I will try to track it down I guess it has to do with session anyway. I also
use the CPM to hold the Model for the whole page. Not a LDM.

Thanks again for the time
Cheers
Niv


On Thu, Dec 2, 2010 at 1:47 PM, Dan Retzlaff dretzl...@gmail.com wrote:

 Hi Nivedan,

 Even though the subsequent requests have a Session open, the entities with
 the uninitialized collections don't know about it. I'm sure if you track it
 down, you can explain the intermittent behavior by prior access to the
 collection when the original session is open.

 I'd say you can either (1) configure Hibernate to load the collections to
 load unlazily, (2) manually access the collections to force them to
 initialize in the specific cases you're encountering LIEs, or (3) employ
 some kind of AOP hack to reinject the new session right before the
 collection is accessed. They're all kind of ugly, and I've never heard of
 anyone else doing the last, but it's been working well for my team.

 For your reference, here is the AspectJ aspect I wrote. (We use Guice for
 dependency injection.)

 /**
  * Reattaches entities whose lazy collections are about to be initialized
  * p
  * Can we keep track of all lazy relationships that get initialized, and
  * uninitialize them at the end of the request? This would prevent
 referenced
  * entities from being serialized and replicated (unless separate
 references
  * were created to them).
  *
  * @author dan
  */
 @Aspect
 public class ReattachAspect {
 private static final Logger LOG = Logger.getLogger(ReattachAspect.class);

 private ProviderSession sessionProvider;

 @Before(call(public final void
 org.hibernate.proxy.AbstractLazyInitializer.initialize()) 
 target(initializer))
 public void reattachLazyInitializer(LazyInitializer initializer) {
 if (initializer.getSession() == null  sessionProvider != null) {
 if (LOG.isDebugEnabled()) {
 LOG.debug(reattaching session to lazy initializer for  +
 initializer.getEntityName());
 }
 Session session = sessionProvider.get();
 initializer.setSession((SessionImplementor) session);
 }
 }

 @Before(call(private void
 org.hibernate.collection.AbstractPersistentCollection
 + .throwLazyInitializationExceptionIfNotConnected()) 
 target(collection))
 public void reattachPersistentCollection(PersistentCollection collection) {
 SessionImplementor session = ((AbstractPersistentCollection)
 collection).getSession();
 if ((session == null || !session.isOpen())  sessionProvider != null) {
 if (LOG.isDebugEnabled()) {
 LOG.debug(reattaching session to collection);
 }

 session = (SessionImplementor) sessionProvider.get();
 CollectionPersister persister =
 session.getFactory().getCollectionPersister(collection.getRole());

 collection.setCurrentSession(session);
 session.getPersistenceContext().addInitializedDetachedCollection(persister,
 collection);
 }
 }

 @Inject
 public void setSessionProvider(ProviderSession sessionProvider) {
 this.sessionProvider = sessionProvider;
 }
 }


 On Wed, Dec 1, 2010 at 9:23 PM, Nivedan Nadaraj shravann...@gmail.com
 wrote:

  Hi All
 
  I am guessing this is more of a Hibernate thing/issue but if some one has
  encountered this and has a explanation that I can probably use from the
  Wicket front would be great.
 
  https://forum.hibernate.org/viewtopic.php?f=1t=1008473
 
 
  I have a LazyIntializationException when i page through some items. I use
  the PageableListView, the List item(s) are entities that are retrieved
 via
  an association Person.phones which is  a Set type.
  The funny thing is, the LIException is intermittent. I am also using
  OpenSessionInViewFilter. Any thoughts?
 
  By the way the this is the load() implemenation, I have set the Model
  Object's phoneList with a list of values fetched via the Service-DAO. I
  have used this with other entities without association and it works  but
 I
  guess is a different scenario(not associations)
 
  Model = new LoadableDetachableModelObject() {
 @Override
  

Re: Wicket-Hibernate Related LazyInitializationException

2010-12-01 Thread Nivedan Nadaraj
Hi James

Thanks for the time. I use the CPM for the whole use case. Mmm..is LDM
mandatory for such a use case? Am open for thoughts just want the best way
to implement it.
Can you explain a bit further what your thought was please?

Thank you
Regards




On Thu, Dec 2, 2010 at 2:13 PM, James Carman ja...@carmanconsulting.comwrote:

 Just make sure your form's model is a LDM too.

 On Thu, Dec 2, 2010 at 12:23 AM, Nivedan Nadaraj shravann...@gmail.com
 wrote:
  Hi All
 
  I am guessing this is more of a Hibernate thing/issue but if some one has
  encountered this and has a explanation that I can probably use from the
  Wicket front would be great.
 
  https://forum.hibernate.org/viewtopic.php?f=1t=1008473
 
 
  I have a LazyIntializationException when i page through some items. I use
  the PageableListView, the List item(s) are entities that are retrieved
 via
  an association Person.phones which is  a Set type.
  The funny thing is, the LIException is intermittent. I am also using
  OpenSessionInViewFilter. Any thoughts?
 
  By the way the this is the load() implemenation, I have set the Model
  Object's phoneList with a list of values fetched via the Service-DAO. I
  have used this with other entities without association and it works  but
 I
  guess is a different scenario(not associations)
 
  Model = new LoadableDetachableModelObject() {
 @Override
 protected Object load() {
 return containerForm.getModelObject().getPhoneList();
 }
 };
  }
 
  If someone has any thoughts would appreiciate hearing from you.
 
 
  Cheers
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org