Issue Details (XML | Word | Printable)

Key: NUCJPA-118
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: FireSign
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Fetching Lazy references with Join Fetch

Created: 18/Mar/11 09:01 PM   Updated: 14/May/12 01:15 PM   Resolved: 14/May/12 01:15 PM
Component/s: API
Affects Version/s: 2.1.7
Fix Version/s: None

File Attachments: 1. Zip Archive lazy-loading.zip (4 kB)

Environment: Windows XP 32 bit, java 1.6.0_21-b07

Datastore: HSQL
Severity: Proof of Concept


 Description  « Hide
Hello,

I have defined a lazy relation in the following JPA Entity:

@Entity
public class Product {
...
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinTable
  private List<ProductProperty> properties;
}

I would like to access the entity and load this reference.

The following query is used:
SELECT DISTINCT p FROM Product p JOIN FETCH p.properties WHERE p.id=:id

After closing the persistency context and accessing the reference (for the first time) the following Exception is thrown:

Exception in thread "main" javax.jdo.JDODetachedFieldAccessException: You have just attempted to access field "properties" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object.

The used versions:
datanucleus core: 2.2.3
datanucleus-jpa.version: 2.1.7
datanucleus enhancer: 2.1.3

Have you got any suggestions?

Sort Order: Ascending order - Click to sort in descending order
FireSign added a comment - 18/Mar/11 09:02 PM
Attaching test files.

Andy Jefferson added a comment - 19/Mar/11 11:44 AM
We don't support fetching defined in queries. This is simply because the mechanism is short-sighted and inadequate. What they are considering adding to the JPA spec for JPA2.1+ is "fetch-groups", which is what JDO has had for the last 6 yrs. DataNucleus already provides this, as described in
http://www.datanucleus.org/products/accessplatform_3_0/jpa/fetchgroup.html

FireSign added a comment - 20/Mar/11 09:00 AM
Hi Andy,
thanks for the clarification.

Andy Jefferson added a comment - 14/May/12 01:15 PM
Refer to NUCRDBMS-592 for fetch loading of 1-1/N-1 references, since these can be accessed/loaded using the same SQL call.
1-N however are not loadable using the same query SQL, and so is just as easy to either use the fetch-group extension that was referred to, or to access the field before commit.