users@glassfish.java.net

How to specify the ubication of JPA configuration files to JPA

From: <glassfish_at_javadesktop.org>
Date: Sat, 05 Jul 2008 18:15:49 PDT

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"));
[Message sent by forum member 'alfonso777' (alfonso777)]

http://forums.java.net/jive/thread.jspa?messageID=284543