Compare old and new schema



I have an old database file with important data. Over time, I have modified some of the entity classes but did not keep track of the changes. Some fields may have been renamed or removed, some classes may have been renamed or changed package.

Is there a way for me to check what "format" the entity classes have in the old database file and compare that with the new classes definitions?




Currently there is no automatic tool to compare the old schema to the new one.

However, you can open the old database in the Explorer (without entity classes in the classpath) and view the content of the old database with the old schema.

ObjectDB Support

Thanks for your answer. Unfortunately, our model has hundreds of classes and therefore a few hundreds attributes. It is feasible but difficult to keep track of all changes such as renaming attributes, renaming classes, package changes etc... All these changes frequently take place between software versions and an automatic comparison of old schema vs new schema is the only reliable way of making sure database migration takes place correctly.

Could you tell me how the explorer gathers the information about the data stored in the database when entity classes are not in the classpath? If I can reproduce this I should be able to get information about the old schema, I would then add the entities to the classloader and get information about the new schema.

I have tried to connect to the "old" db without entity classes in the classpath but the metamodel is empty. How does your explorer get to metamodel?





Would you have any news on this please. This issue is preventing us from releasing a new version of our software.






After investigation it turns out that opening a standard EntityManager while the entity classes are not in the class path allows objectdb to retrieve the data model as it is in the database file rather than the Class hierarchy.

With this in mind, I created a separate project where I opened an EntityManager on a copy of the database file. I can now use a standard getMetamodel() method on the EntityManager to get the database model as it is in the database file.

Now, I need the new Class hierarchy to compare with. To do so, I create a new URLClassLoader with a URL pointing to the folder containing my Class hierarchy like so: 

URLClassLoader classLoader = new URLClassLoader(urlToTheFolderContaingMyEntityClasses, MyCurrentClass.this.getClass().getClassLoader());

Now that I have the Meta Model from the database and the Class hierarchy, I just need to compare each class from the Meta Model with the same class form the Class Hierarchy by loading the class with the new ClassLoader like so:

Class<?> claz = classLoader.loadClass(myClassName);

I hope this helps. If you need more information, let me know.





Thank you for publishing this solution. This is probably the best way to compare schema information in the current ObjectDB version, since the internal ObjectDB versions information is not publicly available now.

ObjectDB Support