Embedding ObjectDB on server application

#1

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!

 

#2

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
#3

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)

javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
extension.LoginEventHandler.handleServerEvent(LoginEventHandler.java:108)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:258)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:764)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchZoneLevelEvent(SFSExtensionManager.java:685)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:882)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:64)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)

 

#4

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

ObjectDB Support
#5

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

#6

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:
Ljavax/persistence/EntityManager;

viewId=/login.xhtml
location=...
phaseId=RENDER_RESPONSE(6)

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?

Reply