Search code examples
javaxmlhibernatederby

set bootPassword for derby database at runtime using hibernate


I use Hibernate and Derby.

I have a hibernate.cfg.xml and all I did for working with db waas to get a Session :

  return new AnnotationConfiguration().configure( "files/hibernate.cfg.xml"   ).buildSessionFactory().getCurrentSession();

my hibernate.cfg.xml containes

   <property name="connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
   <property name="connection.url">jdbc:derby:crmdb;create=true</property>

and some other properties and mappings for entity classes.

now I want to set dataEncryption for derby db and bootPassword at runtime.

I changed hibernate.cfg.xml :

    <property name="connection.url">jdbc:derby:crmdb;create=true;dataEncryption=true;bootPassword=myPass</property>

and everything was ok.

Now I want to set bootPassword at runtime, e.x.by reading from an environment variable. that´s the problem! when I delete "connection.url" from hibernate.cfg.xml and trying to set it inside my code, this error ocurres :

 java.lang.UnsupportedOperationException: The application must supply JDBC connections

and if I delete only bootPassword, it can not connect to db.

any idea ?


Solution

  • It resolved !

    I should set "hibernate.connection.url" instead of "connection.url" !