Groovy JPA example


I've been using Groovy with ObjectDb, just thought I'd post a short snippet to show how easy this is to do.

The following script (which is one import and one statement) will open a database, run a query and print some results.


import javax.persistence.Persistence

.createEntityManagerFactory ("../db1.odb")
.createQuery ("SELECT u FROM User u")
.each {
    println it

Nice. Thanks for sharing it.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Is there a preferred/recommended way to configure DataSource.groovy to connect to the ObjectDB database? As far as I gather, ObjectDB doesn't have the necessary drivers .


ObjectDB doesn't have a JDBC driver, so you cannot configure a JDBC based data source.

You can connect ObjectDB from Groovy as specified in #1 above, or using a persistence.xml file.

Any Groovy library that supports JPA should also work with ObjectDB. If a driver is required you can specify a dummy data source driver (e.g. of another database), and it will be ignored, as long as the connection to ObjectDB is properly set in a persistence.xml file.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

As of 2010, there were plans to make that driver ( Any progress since then? Are there any plans to make a Hibernate Dialect?


A JDBC driver for ObjectDB could be a nice to have feature, but it is currently not in a high priority on our road map.

What do you mean by making a Hibernate dialect? In order to connect Hibernate to ObjectDB?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login