Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Toplink JPA... this should lazy load?

572079Apr 20 2007 — edited Mar 18 2008
My problem is that no matter why I try, Toplink executes way to many SQL statements.

Let's start with a short model description:
- Stand has many StandVersions.
- StandVersions has many StandAssigns.
- StandAssign has one Article.

Scenario: query one Article and count its number of StandAssigns:

Article lArticle = (Article)lEntityManager.createQuery("select a from Article a where a.iArticlenr = 82").getResultList().get(0);
System.out.println("!!! standassigns=" + lArticle.getStandassignsWhereIAmArticle().size());


The getStandassignsWhereIAmArticle in Article just returns this collection:

@OneToMany(mappedBy = "iArticle", fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = nl.reinders.bm.Standassign.class)
private java.util.Collection<nl.reinders.bm.Standassign> iStandassignsWhereIAmArticle;


I would expect this to execute something like the following SQLs:
- select a from Article a where a.articlenr = 82
- select a from StandAssign a where a.articlenr = 82

These two statements are all that is needed to resolve the query. However, the SQLs that actually are executed are many:
- select ... FROM standversion WHERE (standversionnr = ?)
- select ... FROM stand WHERE (standnr = ?)

In effect the whole tree is read, so there is NO lazy loading.

The unittest is started from within Eclipse with the following VM arguments:
-javaagent:lib/toplink-essentials-agent.jar

To allow lazy loading weaving.

What am I missing?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 15 2008
Added on Apr 20 2007
20 comments
4,039 views