How to define database structure and insert some initial objects from scratch

#1

Hi from Spain!

We're evaluating ObjectDB and we have some questions:

- How can we create the initial database structure of our application? We know objectdb is all about objects and probably doesn't need initial structure like tables, but how can we populate some "tables" with initial data from a script? In SQL world we have scripts like "insert into..."

- Can we use main objectdb.jar library as jdbc driver for ETL software like Kettle? How about migrating data from another database system?

Thanks in advance!

#2

To populate the database you will have to write Java code. That code, however, could be simple. Just build your entity objects and persist them. e.g.

public class Main {
    public static void main(String[] args) {

        // Open a database connection
        // (create a new database if it doesn't exist yet):
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("$objectdb/db/points.odb");
        EntityManager em = emf.createEntityManager();

        // Store 1000 Point objects in the database:
        em.getTransaction().begin();
        for (int i = 0; i < 1000; i++) {
            Point p = new Point(i, i);
            em.persist(p);
        }
        em.getTransaction().commit();

        // Close the database connection:
        em.close();
        emf.close();
    }
}

Automatic migration of data from other databases (using JPA) to ObjectDB is expected to be supported later this year. Currently ObjectDB cannot be accessed using JDBC, but this is also something that may be supported in future versions of ObjectDB.

ObjectDB Support

Reply