ObjectDB ObjectDB

@MappedSuperclass and @Transient not working as I expected


The problem could be my expectation, since I'm fairly inexperienced with JPA.  But here is the problem:

The base class of my entity hierarchy is annotated as @MappedSuperclass, and one of its fields is annotated @Transient.  I expected that when I persist a subclass, no table would be created for the superclass, and the transient field would not appear in any table.

The actual result is that there is a table for the superclass.  When I try to examine it in ObjectDB Explorer, it throws a NPE.  And there is a column in the subclass table named for the transient field.  All its values are null.

Here is my base class:

package krum.twj.db;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;

public class DataObject {


protected int id;

protected long version;

protected EntityManagerFactory emf;

protected DataObject merge() {
  //System.err.println("Saving " + this.getClass() + " id " + id + " version " + version);
  EntityManager em = emf.createEntityManager();
  DataObject merged = em.merge(this);
  //System.err.println("Got back id " + merged.id + " version " + merged.version);
  merged.emf = emf;
  return merged;

Your expectations are correct.

Regarding the transient field - it is not stored in the database and the Explorer merely shows default values.

See also this related forum thread.

ObjectDB 2.3 will be released with a new Explorer that should fix the transient field as well as the NPE.

ObjectDB Support

So are the tables that appear for classes annotated @MappedSuperclass also merely stored schemas, without the data?

(I could probably figure this out with a hex editor, but it'd be nice to know what the designers' intentions and future plans are.)


ObjectDB is not an RDBMS so there are no tables, but indeed a mapped superclasses (as well as abstract entity classes) do not store data just schema.

Usually data in ObjectDB consumes much less space than the same data in a JPA/RDBMS combination.

ObjectDB Support


To post on this website please sign in.