Hi everybody,
I'm stucked since two days working on my app because of the hibernate.cfg.xml that my app can't find.
I get the following error at runtime (i put the command line and everything else):
Code:
D:\java\workspace\cs2ra>java -classpath ".;D:\java\workspace\config\bup\*;D:\jav
a\workspace\cs2ra\target\*" -jar target/cs2ra-1.0.0-jar-with-dependencies.jar -
i ../clearingExport_1309770277873.xml -schema repclr_main -cfgfile hibernate.cfg
.xml
getInstance
processing param
../clearingExport_1309770277873.xml
repclr_main
hibernate.cfg.xml
1
17:54:02,023 INFO Version:37 - Hibernate Commons Annotations 3.2.0.Final
17:54:02,029 INFO Environment:593 - Hibernate 3.6.3.Final
17:54:02,032 INFO Environment:626 - hibernate.properties not found
17:54:02,035 INFO Environment:804 - Bytecode provider name : javassist
17:54:02,038 INFO Environment:685 - using JDK 1.4 java.sql.Timestamp handling
2
3
config filenamehibernate.cfg.xml
17:54:02,079 INFO Configuration:2129 - configuring from resource: /hibernate.cf
g.xml
17:54:02,080 INFO Configuration:2148 - Configuration resource: /hibernate.cfg.x
ml
Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibern
ate.cfg.xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
at be.awl.clearing.cs2ra.util.HibernateUtil.buildSessionFactory(Hibernat
eUtil.java:44)
at be.awl.clearing.cs2ra.util.HibernateUtil.<clinit>(HibernateUtil.java:
20)
at be.awl.clearing.cs2ra.App.main(App.java:68)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java
:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configura
tion.java:2149)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2130)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2110)
at be.awl.clearing.cs2ra.util.HibernateUtil.buildSessionFactory(Hibernat
eUtil.java:33)
... 2 more
So, for understanding, here is the structure of my workspace :
2 directories : one for the app (CS2RA) and one for the config files containing X directories with each time a dedicated version of hibernate.cfg.xml.
CONFIG
\------ENV1
.................\hibernate.cfg.xml
\------ENV2
.................\hibernate.cfg.xml
\------ENV3
.................\hibernate.cfg.xml
...
CS2RA
\=> everything develloped with eclipse.
As constraints, i have to give as parameters the database schema, the input file.
Concerning the hibernate.cfg.xml, i tried to modified the classpath when launching the app: i thought it was working but it doesn't.
So from this point, i decided to also pass the hibernate.cfg.xml as a parameter.
so, in HibernateUtil i made the following code:
Code:
/**
*
* @author olivier
*/
import java.io.File;
import java.net.URL;
import be.awl.clearing.cs2ra.App;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
Configuration conf = new Configuration();
File u = new File(App.getConfig_name());
conf.configure().setProperty("hibernate.default_schema", App.getSchema_name());
return conf.configure(u).buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
getSessionFactory().close();
}
}
I found that it's the method
Quote:
conf.configure(u)
which causes my app to crash.
I tried multiple things but never managed to get this working.
Maybe i did it the wrong way, so you'll understand i'm kinda lost :s
Thanks in advance for your advice,
Best regards,
Noshitheel