Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to specify anywhere ubication of JPA configuration files to JPA ?

843830Jul 6 2008
How I specify a directory any where are the configuration files of JPA, i.e persitence.xml and orm.xml.

For example, I have a directory named \jpafiles and here are the persistence.xml and other mapping files, then in a application how to do for indicate that the mapping files are located into ...\jpafiles ?.

As well as Hibernate, by using a instance of Configuration, for example:


String jpafile="....\persistence.xml "; //path relative or absolute
String mapdir="...\orm.xml"; //path relative or absolute
Configuration cfg= new Configuration();

File cfgFile = new File(jpafile);
File cfgDir = new File(mapdir);

if( cfgDir != null && cfgDir.length() > 0){
cfg.addDirectory(cfgDir);
}

if( cfgFile != null && cfgFile.length() > 0){
cfg.configure(cfgFile);
}else{
//File configFile = new File(jpaURL.getPath() + "/persistence.xml");
File configFile = new File(jpaURL.getPath() + "/persistence.xml");
cfg.configure(configFile);
}

...
Class driverClass = testLoader.loadClass(cfg.getProperty("connection.driver_class"));

Driver driver = (Driver) driverClass.newInstance( );
WrappedDriver wd = new WrappedDriver( driver,
cfg.getProperty("connection.driver_class"));

Are there any way using the Api in JPA? or Is there any way to do?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2008
Added on Jul 6 2008
0 comments
156 views