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 T326 {
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.