是我的Java文件中的代码段代码,但在打印label:1后,它给了我异常。
try{
logger.debug(Logger.formatLog("label:1"));
org.hibernate.cfg.Configuration con = new Configuration();
logger.debug(Logger.formatLog("label:2"));
File hiberConfFile=new File("/cfg/hibernate/hibernate.cfg.xml");
//I am on Unix Env and directory structure is RUN/cfg and RUN/lib and my java file is in lib dir ,However I have not got any kind of parsing or FileNotfoundException.
logger.debug(Logger.formatLog("label:3"));
con.configure(hiberConfFile);
logger.debug(Logger.formatLog("label:4"));
con.setProperty(USERNAME, dbInfo.getUsername());
logger.debug(Logger.formatLog("UserName:" + con.getProperty(USERNAME)));
con.setProperty(PASSWORD, dbInfo.getPassword());
logger.debug(Logger.formatLog("PASSWORD:" + con.getProperty(PASSWORD)));
con.setProperty(URL, ORACLE+dbInfo.getHost()+":"+dbInfo.getPort()+":"+dbInfo.getSid());
logger.debug(Logger.formatLog("Connection URL:" + con.getProperty(URL)));
factory =con.configure("hibernate.cfg.xml");
serviceRegistry = new ServiceRegistryBuilder().applySettings(con.getProperties()).buildServiceRegistry();
factory = con.buildSessionFactory(serviceRegistry);
factory=con.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
results = session.createQuery(query).list();
tx.commit();
}catch (Throwable ex) {
logger.debug(Logger.formatLog(("Initial SessionFactory creation failed." + ex)));
ex.getCause().printStackTrace();
}
在Label之后在Hibernates中创建配置对象之前获得以下错误:1 初始SessionFactory创建失败.java.lang.ExceptionInInitializerError c.C.S.C.D.D.DBConnector.sendQuery.173
显示java.lang.NullPointerException 在org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170) 在org.hibernate.cfg.Environment。(Environment.java:221) 在org.hibernate.cfg.Configuration.reset(Configuration.java:300) 在org.hibernate.cfg.Configuration。(Configuration.java:266) 在org.hibernate.cfg.Configuration。(Configuration.java:270) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305) at sun.rmi.transport.Transport $ 1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908) 在java.lang.Thread.run(Thread.java:619)
任何人都可以帮我解决这个问题吗?