Search code examples
javaembedded-databaseobjectdb

ObjectDB Connection in Eclipse


I am very new to the ObjectDB. The reason I am trying to use this is to create desktop java application using embedded database. In other words, I ultimately want to give my friend a runnable jar file alone so he can access the database in javaFX application without bothering anything such as server.

According to the mannual, I have to use the EntityManagerFactory like this:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("$objectdb/db/points.odb");

The mannual says "The createEntityManagerFactory static method expects a persistence unit name as an argument, but when using ObjectDB, any valid database file path is also accepted."

So far, I created an Entity Class and then the tutorial suddenly introduced that. I am lost at the argument of the EntityManaferFacotory method. All I have is an Entity class. What is about the database file?

and would you give me an idea how to embed database into jar file? Like where to place certain file or certain way to put file path?


Solution

  • The database file will be created automatically if it does not exist yet, so the parameter of createEntityManagerFactory could be simply a path to the database file, where $objectdb represents the ObjectDB home directory.