Embedding ObjectDB on server application


I'm trying to integrate ObjectDB as part of a server software I am developing. I'm a little lost at the connection file path for the persistent factory. So if I want to pass in the database file path, with relative path, where exactly is it relative to?

So I did a test and just wrote:

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("test.odb");

But I got:

Exception: javax.persistence.PersistenceException
Message: No Persistence provider for EntityManager named test.odb

Shouldn't the method automatically create a database if it doesn't exist already?

Just started trying out ObjectDB so sorry if I didn't read the documents carefully enough!



The error message that you get may indicate that objectdb.jar is not found in the classpath (i.e. JPA is available but not ObjectDB). It could also happen if the path that you specify is not recognized by ObjectDB, but a path with a suffix .odb should be recognized (for other paths add the prefix objectdb:)

Relative path is relative to the OS current directory (which is out of control of ObjectDB).

If you specify the following path: objectdb:$objectdb/test.odb, then it is relative to the ObjectDB home directory.

ObjectDB Support

I double checked that ObjectDB.jar is indeed imported into the project...at least on Eclipse. Is there some way I can check on runtime?

Still getting this:

Message: No Persistence provider for EntityManager named objectdb:$objectdb/test.odb
Description: Error during event handling: javax.persistence.PersistenceException: No Persistence provider for EntityManager named objectdb:$objectdb/test.odb

Is it possible to get this exception if ObjectDB is unable to create a file at the requested directory?

Here's the stack trace: (starting on 4th line is server app's trace)




It looks like a classpath issue. Maybe objectdb.jar is available only in compilation and not at runtime.

ObjectDB Support

That is precisely the issue! Since I have to export the project from eclipse, the server middleware is responsible to load the jars dependencies, and objectdb wasn't getting loaded somehow.

I came up with a workaround and it's now working! Thanks :)


It seems like I have a smiliar problem... I'm working with Eclipse and Maven. I added the objectdb.jar-File as an external Jar to my Project. Eclipse does not show any errors and it looks like it finds all classes (autocomplete is working). But when I run the project I get this error message:

An Error Occurred:


Caused by:
java.lang.ClassNotFoundException - javax.persistence.EntityManager
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)

What can I do to fix it?