I’m a newbie to JPA, hibernate and Java itself.
I have somehow made my code work to access values from a DB.
When I extract my final jar of jars, I have a META-INF directory which has persistence.xml in it.
The hibernate.properties and hibernate.cfg.xml are also inside my jar.
So at runtime I’m unable to do any changes to these files since everything is inside jar.
I want to move persistence.xml, hibernate.cfg.xml and hibernate.properties outside jar and place them somewhere in deployment environment. I can do this but I don’t know how to write Java Code to let hibernate know where to look for these files.
E.g. for log4j I can use PropertyConfigurator.configure(“/opt/somepath/log4j.properties”) and tell log4j where log4j.properties file is present.
Could anyone please help me and direct me to some links where I can learn to load configuration for JPA and hibernate at runtime ?
I want to point to different DBs at runtime and test them without changing my jar of jars.
jpa/hibernate scans classpath where looking for configuration files. You can always add to classpath directory/directories.
Put
META-INF directoryto ${MY_DIR1} ( or/and ${MY_DIR2})