Yes, iBATIS allows lazy loading across connections. Be warned though, we allow this, but it does create the potential for inconsistent data. For example:
1. Parent object is loaded (complex associations and collections are not, proxy stubs are put in their place). 2. Some of the related data is changed. 3. Complex associations are loaded. This means that the Parent object and one of its associations were loaded in different contexts and it's possible that their states are inconsistent. JPA disallows this for this reason, but being an ORM, it also has the ability to reload/refresh the parent object if necessary. We leave it up to you to deal with this situation. Many times this is perfectly safe (immutable data, private data to a single user, etc.). Other times though, you'll want to be careful. Cheers, Clinton On Mon, Feb 1, 2010 at 6:56 PM, Daryl Stultz <da...@6degrees.com> wrote: > Hello, > > I am investigation iBatis as an alternative to JPA/OpenJPA. JPA states that > the behavior of the provider in the case of accessing unloaded fields on a > "detached" object is "unspecified". OpenJPA returns null or throws an > exception depending on the configuration. Considering the test case below, > it appears that iBatis can lazy load fields outside of the session that > instantiated it. Is this true or have I misinterpreted my code? If it can > lazy load after the session is closed, that would be AWESOME! That would > mean that eager loading is merely an optimization and not a requirement for > object manipulation that takes place over multiple "user interactions". If > it's true, exactly how does it work? I'm using CGLIB. Does the enhanced > class keep a reference to the original DataSource for getting a new > connection? Or is there some ThreadLocal work going on? Do I need to extend > my test case to spin up another Thread? Thanks. > > UserType ut = *new* UserType(); > > ut.setName("doctor"); > > UserTypeMapper utm = session.getMapper(UserTypeMapper.*class*); > > utm.insert(ut); > > session.commit(); > > *assertNotNull*(ut.getId()); > > User user = *new* User(); > > user.setName("Fred"); > > user.setUserType(ut); > > UserMapper um = session.getMapper(UserMapper.*class*); > > um.insert(user); > > session.commit(); > > *assertNotNull*(user.getId()); > > session.close(); > > session = factory.openSession(); > > um = session.getMapper(UserMapper.*class*); > > user = um.findById(user.getId()); > > session.close(); > > *assertEquals*("Fred", user.getName()); > > *assertNotNull*(user.getUserType()); // lazy loading > > *assertEquals*("doctor", user.getUserType().getName()); > > *assertEquals*(ut.getId(), user.getUserType().getId()); > > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:da...@6degrees.com >