ObjectDB ObjectDB

Failed to write the value of field using reflection (error 363) on LAZY fetch

#1

Hi There I am using ObjectDB 2.6.3. I get the following Exception when I try to read my entities with a query where I have set to use LAZY initalization. It fails when it tries to set a 1:n member (e.g. a Modell has several Artikels) . When I remove the LAZY hint (query.setHint("objectdb.result-fetch", "LAZY");) on the query execution it works.

I assume it has to do with the @Transactional context, that when my query-method "getEntities()" ends the transaction get closed and no longer a "connection" to load the detaild objects can be made? If so how can I keep the transaction open when I am using a spring context (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)?

Any hints?

The Mapping of class Modell and its member:


@Entity
class Modell {
...

@OneToMany(fetch=FetchType.LAZY, mappedBy="modell", cascade=CascadeType.ALL)
private List<Artikel> articles = new ArrayList<Artikel>();

public void addArtikel(Artikel artikel) {
  if (!articles.contains(artikel)) {
   this.articles.add(artikel);
    artikel.setModell(this);
  }
}

public List<Artikel> getArticles() {
  return articles;
}

public void setArticles(List<Artikel> articles) {
  this.articles = articles;
}
...
}

 

The Query

    @Transactional (readOnly=true)
    protected List<T> getEntities(Class<T> classEntity) {
TypedQuery<T> query = getEntityManager().createQuery(String.format("SELECT e FROM %s e",classEntity.getSimpleName()), classEntity);
    query.setHint("objectdb.result-fetch", "LAZY");
    List<T> entities = query.getResultList();
}

Stack Trace

Exception in thread "main" [ObjectDB 2.6.3] javax.persistence.PersistenceException
Failed to write the value of field field ch.megloff.zeus.model.Modell.articles using reflection (error 363)
at ch.megloff.zeus.importer.ZeusImport.run(ZeusImport.java:94)
at ch.megloff.zeus.importer.ZeusImport.main(ZeusImport.java:45)
Caused by: com.objectdb.o.UserException: Failed to write the value of field field ch.megloff.zeus.model.Modell.articles using reflection
at com.objectdb.o.MSG.d(MSG.java:75)
at com.objectdb.o.UMR.P(UMR.java:934)
at com.objectdb.o.UMR.z(UMR.java:574)
at com.objectdb.o.UML.u(UML.java:537)
at com.objectdb.o.ENH.d(ENH.java:236)
at com.objectdb.o.ENT.Z(ENT.java:902)
at com.objectdb.o.LDR.K(LDR.java:844)
at com.objectdb.o.LDR.J(LDR.java:804)
at com.objectdb.o.LDR.U1(LDR.java:1031)
at com.objectdb.o.CST.ac(CST.java:578)
at com.objectdb.o.CST.U9(CST.java:502)
at com.objectdb.o.LDR.F(LDR.java:563)
at com.objectdb.o.LDR.E(LDR.java:470)
at com.objectdb.o.OBC.UO(OBC.java:1080)
at com.objectdb.o.RSL.r(RSL.java:321)
at com.objectdb.o.RSL.get(RSL.java:169)
... 4 more
Caused by: java.lang.NullPointerException
at com.objectdb.o.ILP.isEmpty(ILP.java:157)
at com.objectdb.o.TYW.ar(TYW.java:481)
at com.objectdb.o.TYW.writeElement(TYW.java:309)
at com.objectdb.o.UMR$S.A(UMR.java:1001)
at com.objectdb.o.UMR.z(UMR.java:571)
... 17 more


 

 

edit
delete
#2

Please see this thread that also suggests a new setting ("objectdb.temp.no-detach") that may be useful for you.

Regarding setting Spring Framework transactions in a way that JPA managed entities will not be detached on exiting a method, please check Spring Framework documentation and their Forum.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.