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


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:

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)) {

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.main(
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(
at com.objectdb.o.UMR.P(
at com.objectdb.o.UMR.z(
at com.objectdb.o.UML.u(
at com.objectdb.o.ENH.d(
at com.objectdb.o.ENT.Z(
at com.objectdb.o.LDR.K(
at com.objectdb.o.LDR.J(
at com.objectdb.o.LDR.U1(
at com.objectdb.o.CST.U9(
at com.objectdb.o.LDR.F(
at com.objectdb.o.LDR.E(
at com.objectdb.o.OBC.UO(
at com.objectdb.o.RSL.r(
at com.objectdb.o.RSL.get(
... 4 more
Caused by: java.lang.NullPointerException
at com.objectdb.o.ILP.isEmpty(
at com.objectdb.o.TYW.writeElement(
at com.objectdb.o.UMR$S.A(
at com.objectdb.o.UMR.z(
... 17 more




Please see this thread that also suggests a new setting ("") 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
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login