Issue #1997: Schema-Update: Deactivation of automatic entity class removing and introduction of a new class remove in the schema config

Type: Feature RequestVersion: 2.7.1Priority: HighStatus: ActiveReplies: 4
#1

Hello,

in our application we use ObjectDB in embedded mode as part of the Profile that can be stored and opened by our customers. Our application is an eclipse RCP application with a domain-driven design. The product can be installed in different configurations (in other words with more or less PlugIns).


This presents us with further challenges when we have made changes to DB schema for new versions.

Our solution is that we create a seperate product (we call it ProfileMigration) for each new application to handle all database (schema) changes between two versions. That this ProfileMigration works correctly we add ALL entity classes to this product. Because we will prevent a data loss of entites which are not found in the class path.

With this background it would be very helpful for us if we could ignore in the ProfileMigration the classes we had not changed. And we were able to explicitly define the classes, in the schema config (objectdb.config), that should be deleted.

 

In the future we plan to extends our application via plugins and then we will get problems with our update concept, because it would be a very big effort to recognize data of plugins in the ProfileMigration and to provide for the ProfileMigration application also a plugin which contains the entity classes.

 

We appreciate the other features of the automatic schema update very much.

#2

Hello,

we got now an exception in a use case in which we removed an entity.

Exception in thread "main" java.lang.AbstractMethodError: removedSubClass.ChildClass.__odbSetTracker(Lcom/objectdb/spi/Tracker;)V
at com.objectdb.o.OBC.az(OBC.java:461)
at com.objectdb.o.OBC.aN(OBC.java:951)
at com.objectdb.o.OBC.UM(OBC.java:795)
at com.objectdb.o.SRB.l(SRB.java:160)
at com.objectdb.o.QRR.m(QRR.java:549)
at com.objectdb.o.QRR.f(QRR.java:212)
at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:716)
at removedSubClass.UpdateDB.main(UpdateDB.java:27)

We tried to reproduce the issue and find out that we get the exception only if we didn't enhanced the classes.

But we also observed that we can access the persisted objects of the 'removed' entity. And now we are a little bit confused, because we thought that the instances are removed if we remove the entity class.

In the past we made a small check. We created a Database with many Entities. Opened it with just a few entities, modified some instances and save the Database. And then at least we tried to open the Database with the first Metamodel and tried to access entities they are not part of the second (reduced) schema and it wasn't possible. Therefore our adoption that instances are removed if we removed the entity class.

Our current analysis looks different....

 

We think it's best to explain how the database behaves.
1) How can we delete a whole class?
2) What happens when we open the DB but not all entity classes exist in the classpath?

#3

ObjectDB doesn't currently support removing a class.

You can remove all the objects of a class from the database, of course.

If you open the database and classes are missing - ObjectDB generates them automatically using the stored schema (e.g. this is how the Explorer works).

ObjectDB Support
#4

Hello,

we have continued to observe the behavior.

During our first analysis we just remove the "@Entity" annotations, but the class itself was still available in the classpath. If we complete remove the class, it works as we hoped.

 

Can you please explain what happens, if the entity class is NOT available. Or at least what we have to consider!

As example: If we have an entity 'childEntity' which extends the entity 'masterEntity' and we override a method e.g. incrementSomething() and the entity 'childEntity' is not available the method of the parent is called!

Scenario: We select with a query all instances of 'masterEntity' and then call the incementSomething() method for each entity, then it don't happen what we expected.

May be you know more limitations like this.

 

UPDATE: The described scenario works only with enhanced entities. Otherwise we get an exception:

Exception in thread "main" java.lang.AbstractMethodError: removedSubClass.ChildClass.__odbSetTracker(Lcom/objectdb/spi/Tracker;)V
at com.objectdb.o.OBC.az(OBC.java:463)
at com.objectdb.o.OBC.aN(OBC.java:958)
at com.objectdb.o.OBC.UZ(OBC.java:798)
at com.objectdb.o.SRB.l(SRB.java:160)
at com.objectdb.o.QRR.m(QRR.java:549)
at com.objectdb.o.QRR.f(QRR.java:212)
at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:719)
at removedSubClass.UpdateDB.main(UpdateDB.java:28)
#5

If a class is not available in the classpath but needed by ObjectDB and known (as its schema is already stored in the database) then ObjectDB builds the class dynamically according to the known schema. A synthetically built class contains known fields but methods are not included as they are not recorded in the schema.

ObjectDB Support

Reply