Howdy,
I'm using annotation's but I need to dynamically override/set hibernate.cfg.xml's
/hibernate-configuration/session-factory/property[@name='connection.url'] during initialization.
I've tried a few strategies:
Load hibernate.cfg.xml And Override the Property:Code:
Configuration config = new Configuration();
config.configure();
config.setProperty("hibernate.connection.url", "jdbc:sqlite:" + sqliteFilePath);
session = config.buildSessionFactory().openSession();
But that results in, org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.myproject.MyEntity"/>Programmatically Load a Configuration:Code:
Configuration config = new Configuration();
config.setProperty("hibernate.connection.driver_class", JDBC.class.getName());// JDBC driver class
config.setProperty("hibernate.connection.url", "jdbc:sqlite:" + sqliteFilePath);// JDBC URL
//more properties...
config.addClass(MyEntity.class);
session = config.buildSessionFactory().openSession();
But that'll try and load MyEntity.hbm.xml which does not exist (because I am using annotations).I'm not sure what the magic mix is here, I'm sure it's possible... advice would be great!
--Thanks for reading :)
p.s. the documentation for Programmatic Configuration is
HERE.