Hibernate - 对象创建错误 [英] Hibernate -- object creation error
问题描述
我已经设置并在Eclipse / Juno EE上运行Hibernate 3.6。
我的第一个代码在实例化HN的类配置时给我一个运行时错误。所以 - 确切地说,
SessionFactory aFactory;
配置conf;
都很好&运行,
但下面一行
conf = new配置();
抛出 java.lang.ExceptionInInitializerError 。
$ b
代码
SessionFactory aFactory = new Configuration()。configure ().buildSessionFactory();
无处不在。
我的hibernate.cfg.xml如下:
< ;?xml version ='1.0'encoding ='utf-8'?>
$ b<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate Configuration DTD 3.0 // EN
http://www.hibernate .ORG / DTD /休眠配置-3.0.dtd>
< hibernate-configuration>
< session-factory>
< property name =connection.driver_class> org.postgresql.Driver< / property>
< property name =connection.url> jdbc:postgresql:// localhost:5432 / ThisDB< / property>
< property name =connection.username> postgres< / property>
< property name =connection.password> somePass< / property>
< property name =connection.pool_size> 1< / property>
< property name =dialect> org.hibernate.dialect.PostgreSQLDialect< / property>
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
< property name =show_sql> true< / property>
< property name =hbm2ddl.auto>建立< / property>
< mapping class =dataObjs.someItems/>
< / session-factory>
< / hibernate-configuration>
我从同一个项目中复制了!DOCTYPE标记
的内容我下载的包 - 所以它应该没问题。
我的库全部添加到项目中并导入到类中。
代码在创建非Hibernate对象时没有提供任何此类错误。
我缺少什么?
HN的新功能。这是我的第一个代码。
// ================================= ====
编辑:添加代码& stacktrace:
package somePaket;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入dataObjs.someItems;
public class firstClass {
public static void main(String [] args){
System.out.println(.......... see this .........);
someItems kullanici = new someItems();
itm.setID(1);
itm.setType(aaa);
SessionFactory aFactory;
配置conf = new配置();;
新配置();
新配置()。configure()。buildSessionFactory();
完整登录控制台:
..........看到.........
SLF4J:加载类失败org.slf4j.impl.StaticLoggerBinder。
SLF4J:默认为无操作(NOP)记录器实现
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。
在线程main中的异常java.lang.ExceptionInInitializerError $ b $在org.hibernate.cfg.Configuration.reset(Configuration.java:332)
在org.hibernate.cfg.Configuration。< ; init>(Configuration.java:298)
at org.hibernate.cfg.Configuration。< init>(Configuration.java:302)
at somePaket.firstClass.main(firstClass.java:18 )
导致:java.lang.NullPointerException $ b $ org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
org.hibernate.cfg.Environment。< clinit> ;(Environment.java:618)
... 4 more
// == ===================
EDIT2:
在调试器中追踪它:
LoggerFactory.singleImplementationSanityCheck()
在其行216处引用以下内容:
FileNotFoundException(Throwable )。< init>(String)line:264.
> slf4j-simple-1.6.2.jar
I've set up and am running Hibernate 3.6 on Eclipse/Juno EE.
My first code is giving me a runtime error on instantiating the class Configuration of HN. So-- to be precise,
SessionFactory aFactory;
Configuration conf;
are fine & running,
but the line next below
conf=new Configuration();
is throwing java.lang.ExceptionInInitializerError.
The code
SessionFactory aFactory = new Configuration().configure().buildSessionFactory();
is nowhere near running.
My hibernate.cfg.xml is as follows:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/ThisDB</property>
<property name="connection.username">postgres</property>
<property name="connection.password">somePass</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="dataObjs.someItems"/>
</session-factory>
</hibernate-configuration>
I copied the contents of the "!DOCTYPE" tag from a project in the same pack I downloaded-- so it should be fine.
My libraries are all added to the project and are imported in the class.
The code is not giving any such errors on creation of "non-Hibernate" objects.
What am i missing?
New to HN. this my first code.
//=====================================
EDIT: Adding the code & the stacktrace:
package somePaket;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import dataObjs.someItems;
public class firstClass{
public static void main(String[] args) {
System.out.println("..........see this.........");
someItems kullanici = new someItems();
itm.setID(1);
itm.setType("aaa");
SessionFactory aFactory;
Configuration conf=new Configuration();;
new Configuration();
new Configuration().configure().buildSessionFactory();
}
}
the full log on Console:
..........see this.........
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:332)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:298)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:302)
at somePaket.firstClass.main(firstClass.java:18)
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:618)
... 4 more
//=====================
EDIT2:
Traced it in Debugger:
LoggerFactory.singleImplementationSanityCheck()
is throwing the following at its line 216:
FileNotFoundException(Throwable).<init>(String) line: 264.
You may have to include your slf4j library with the application:
slf4j-simple-1.6.2.jar
这篇关于Hibernate - 对象创建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!