Announcement Announcement Module
No announcement yet.
"failed to lazily initialize a collection" behaviour Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by pierdeux View Post
    That's a pretty bold statement...

    For the sake of argument and for my own learning, what kind of test would be acceptable as a proof that it does work?
    Well, not getting lazy loading exceptions for starters.


    • #17
      Hi, I think that:

      a) works because you refresh the region. Refreshing a detached object, initialize it and cascade the refresh to his childs.

      b) Don't work because you never initialize the regionLocalized Map, so calling get() will throw a LazyUnitializedException. Getting a entry of a collection don't initialize the collection itself. Initilializing a Collection, don't ensure that elements are initialized.

      If you simply initialize collection and the elements you need before returning from fully* methods, both will work.

      public class RegionDao extends HibernateDaoSupport {
      	public void fullyLoadA(final Region region, final Language lang) {
      		getHibernateTemplate().execute(new HibernateCallback() {
      			public Object doInHibernate(Session session) throws HibernateException, SQLException {
      				return null;
      	public void fullyLoadB(Region region, Language lang) {
      		region = (Region) getHibernateTemplate().load(Region.class, region.getId());



      • #18
        Now come on, guys. We're not in kindergarten.
        of course we are not, and is not necessary your agression, i am try to help you

        I am not posting my entire application
        of course not

        You can assume that inServiceLayer() is defined inside the SystemArchitecture class (which I did not provide either).
        now you must assume that a DAO object must be wrapped by a BO object and this managed by Spring Transaction so.

        What I can say is that I have used that transaction setup for about 12 months, all the while reading, writing, updating and deleting from the database, committing and rolling back transactions, and running tests upon tests. I have got 12 months of practical success with that transaction setup.
        wondered after 12 months you have problems now

        what would be universally considered as a good test of such a transaction setup?
        here some help
        Last edited by dr_pompeii; Aug 28th, 2008, 08:28 AM.


        • #19
          Originally posted by dejanp View Post
          Well, not getting lazy loading exceptions for starters.
          the last line in loadedB could be
"within loadedB: " + region.getLocalized().get(Language.EN));
          if this succeeds, then the initialisation worked correctly.

          failure would indicate a difference between the code behind Hibernate.initialize() and getHibernateTemplate().initialize().

          what i was getting at earlier was a difference between refresh (which uses original object) and load (which creates a new object).