-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate connection properties in OSGI
PostPosted: Tue Jul 08, 2014 12:49 pm 
Newbie

Joined: Tue Jul 08, 2014 12:29 pm
Posts: 1
Background

We have old database code (Hibernate 3.2.4.ga) that would manually create session factories with application configurable settings like this:

Code:
Configuration hibernateConfiguration =
    new Configuration().configure( hibernateConfigurationUrl )
                .setProperty( "hibernate.connection.driver_class", JDBC_DRIVERCLASS )
                .setProperty( "hibernate.connection.url", JDBC_URL )
                .setProperty( "hibernate.connection.username", JDBC_USERNAME )
                .setProperty( "hibernate.connection.password", JDBC_PASSWORD )
                .setProperty( "hibernate.dialect",  HIBERNATE_DIALECT );


This code was used in OSGi (Apache Felix). We are updating to a newer OSGi platform, Apache Karaf 3.0.1. I am attempting to update our software to use a newer hibernate (4.3.1.Final) in order to move things closer to doing things the 'right way' in OSGi with hibernate. In order to not have to rewrite all of our database code to use JPA, we would like to use unmanaged native hibernate mode in OSGi. I know in OSGi unmanaged native mode, you are supposed to access the session factory with osgi services, but in that case, the session factory is already created with the configuration in the jar.

The Problem

The problem I am trying to figure out has to do with configuring hibernate with one or more hibernate.cfg.xml files. The examples I see embed the connection information right in the hibernate.cfg.xml that gets put in the jar. I would rather not have our database connection information hardcoded right in the jar, and would rather it be something we can have in configuration files that gets pulled in. Is there a way to support this with hibernate osgi in unmanaged native mode?

I would like the following to be able to be set by my software, not by a 'hardcoded' xml file in the jar:

Code:
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/mydbname</property>
        <property name="hibernate.connection.username">mydbuser</property>
        <property name="hibernate.connection.password">mydbpass</property>


It would even be okay for the hibernate.cfg.xml to be loaded seperately from the jar, but I just have not been able to figure out a way to do that. Any help would be appreciated.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.