521 words

Issue #48 - Navigation through lazy loading from Detached Objects

Feature RequestVersion: 2.2.6Priority: NormalStatus: ActiveReplies: 4
#1
2011-06-05 07:47

A main limitation of detached objects (as explained on the Detached Entities manual page) is:

  • Retrieval by navigation from detached objects is not supported, so only persistent fields that have been loaded before detachment should be used.

As explained on the Object DB vs EclipseLink/TopLink: on accessing lazy loaded relationships outside a transaction, after a query, from Glassfish forum thread - this JPA limitation is avoided in EclipseLink by an extension, which keep detached objects in a semi detached state (in which they are still associated with the EntityManagerFactory and enable  lazy loading) - until serialization, which completes the detachment.

It seems that implementing a similar extension in ObjectDB would ease emigration of web applications from EclipseLink to ObjectDB.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #335
#2
2012-01-27 00:58

Just an update to confirm my very strong interest in this feature.
We simply can't use our EclipseLink-based JavaEE (JPA+JSF) web application with ObjectDB otherwise.

We are very interested in using ObjectDB technology after a very promising evaluation (thanks for that)
but for us the inability to navigate lazy relationships of detached entities is a big showstopper,
as we rely on that capability heavily in our web application, especially from JSF, pulling very complex
data and relationships as and when needed. We do not want to write 1000s of dedicated projection queries 
and/or fetch joins that can preempty data that will be needed in the user interface.

[Recommended reading JPA Pro 2:

- p.164 to p.168 Working with Detached Entities

- p.222 Fetch Joins

]

We appreciate that this feature, available in some other JPA providers, goes beyond the requirements and spec of JPA2.

It will however make it much easier for many people who have coded against EclipseLink to migrate to ObjectDB.

thanks,

Webel

PS: have upgrade to critical because for us it is, we simply can't use ObjectDB for our system as coded.

--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au
webel
webel's picture
Joined on 2011-05-27
User Post #29
#3
2012-02-03 12:09

Build 2.3.6_16 includes an initial attempt to provide some sort of basic support of this feature.

A new system property ("objectdb.temp.no-detach") can be set to disable detachment of objects. Basically that is what EclipseLink does. Entity objects are not really detached when using EclipseLink.

The following test demonstrates how it works:

import java.util.*;
 
import javax.persistence.*;
 
public final class I48 {
 
    public static void main(String[] args) {
 
        // System.setProperty("objectdb.temp.no-detach", "true");
 
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb:$objectdb/test.tmp;drop");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        MyEntity e1 = new MyEntity(1, "e1");
        MyEntity e2 = new MyEntity(2, "e2");
        e1.list = Collections.singletonList(e2);
        em.persist(e1);
        em.getTransaction().commit();
        System.out.println(e1);
        em.close();
        emf.close();
 
        emf = Persistence.createEntityManagerFactory(
            "objectdb:$objectdb/test.tmp");
        em = emf.createEntityManager();
        e1 = em.find(MyEntity.class, 1);
        em.close();
        emf.close();
        System.out.println(e1);
    }
 
    @Entity
    static final class MyEntity {
        @Id int id;
        String str;
 
        @OneToMany(cascade=CascadeType.PERSIST)
        List<MyEntity> list;
 
        MyEntity() {
        }
 
        MyEntity(int id, String str) {
            this.id = id;
            this.str = str;
        }
 
        @Override
        public String toString() {
            return id + "->" + str + ":" + list;
        }
    }
}

When the line that sets the system property is commented the output is:

1->e1:[2->e2:null]
1->e1:[]

and when that line is active the output is:

1->e1:[2->e2:null]
1->e1:[2->e2:null]

This is by no way a complete solution. It is merely disables detachment. The effect is unclear yet, but for example, it could affect memory consumption and file closing if detached objects (which are not detached anymore) have long life.

So feedback is needed.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #904
#4
2012-02-06 01:18

confirming have read and will try, thanks, Webel.

--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au
webel
webel's picture
Joined on 2011-05-27
User Post #31
#5
2012-02-16 13:59

Build 2.3.7_01 fixes NullPointerException in accessing inverse (mapped by) fields after detachment.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #925

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel