Home » Support » Forum » Configure ObjectDB in spring context

Configure ObjectDB in spring context


I have a application that initializes with spring, now I'd like to change my data access tier to ObjectDB (from Hibernate : HSQL), but I couldn't find any useful information on it.

My goal is to configure entire ObjectDB (optionally objectdb.conf too) in springs context.xml file so that I'd be able to inject EntityManagerFactory to my beans.

Could you help me on this?


You can see how to use ObjectDB with Spring Framework in this tutorial.

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

Yes I've seen that option, but my application is not an MVC, its just pure Spring application and I need to avoid creating persistance.xml file.

My previous database.xml (which is included in application-context.xml) look like this

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

    <!--Defining DataSource-->
    <bean id="dataSource"
        <property name="driverClassName" value="org.hibernate.dialect.HSQLDialect"/>
        <property name="url" value="jdbc:hsqldb:file:db/jminer"/>
        <property name="username" value="sa"/>
        <property name="password" value=""/>

    <!--Defining Hibernate Configurations-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.jminer.core.persistence"/>
        <property name="hibernateProperties">
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.connection.pool_size">10</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">false</prop>
                <prop key="hibernate.cache.use_query_cache">false</prop>
                <prop key="hibernate.hbm2ddl.auto">create-drop</prop>

I need to keep this structure, and define all my database related properties in this file... Can you help me on this? 

I've tried this

<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="url" value="$objectdb/db/guests.odb"/>
        <property name="username" value="admin"/>
        <property name="password" value="admin"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="datasource"/>
        <property name="persistenceProviderClass" value="com.objectdb.jpa.Provider"/>

for this i need to know ObjectDB data source driver class name... If I don't understand something or missing anything here please fix me.

Also I need to have there ObjectDB specific properties 

  <general> ... </general>
  <database> ... </database>
  <entities>  ... </entities>
  <schema> ... </schema>
  <server> ... </server>
  <users> ... </users>
  <ssl> ... </ssl>

if possible at all...


ObjectDB does not have a data source driver class name. Sometimes when it is requested, any data source driver class name (which is not related to ObjectDB) can be specified, and if passed to ObjectDB it is simply ignored. But I am not sure how it will work with these Spring Framework beans.

Regarding the ObjectDB configuration, it must be placed in an objectdb.conf file. But you can also replace the objectdb.conf resource that is embedded in the objectdb.jar file, and then no external file will be needed.

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

Hi, I've found my solution partially. In case if anyone will need something like this...

        value = {
public class ApplicationConfig {

    private Environment environment;

    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(ApplicationConfig.class);

    public JpaTransactionManager transactionManager() throws ClassNotFoundException {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        return transactionManager;

    public EntityManagerFactory entityManagerFactory() throws ClassNotFoundException {
        System.setProperty("objectdb.home", environment.getRequiredProperty("objectdb.home"));
        System.setProperty("objectdb.conf", environment.getRequiredProperty("objectdb.conf"));
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(environment.getRequiredProperty("objectdb.db.url"));
        return emf;


I've used JavaConfiguration style of spring and included my xml configurations... Looks even better.

Post Reply

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