- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
使用 Eclipse+Hibernate+Oracle 9,我的测试应用程序(在 Eclipse 内运行)返回此错误:
"Failed to create sessionFactory object.org.hibernate.HibernateException: could not init listeners"
(用引号谷歌搜索,什么也找不到)
我是 Hibernate 新手,我想将其添加到现有的 web 应用程序项目中,但有以下限制:
Java 1.5.0_22
eclipse 赫利俄斯
Oracle 9
所以我选择兼容的Hibernate 3.6.10。
一切都可以编译。 jar 和构建路径似乎没问题。在 Eclipse 中运行我的应用程序,控制台显示以下内容:
- Hibernate Commons Annotations 3.2.0.Final
- Hibernate 3.6.10.Final
- hibernate.properties not found
- Bytecode provider name : javassist
- using JDK 1.4 java.sql.Timestamp handling
- configuring from resource: ext\als\hibernate\hibernate.cfg.xml
- Configuration resource: ext\als\hibernate\hibernate.cfg.xml
- Reading mappings from resource : ext\als\hibernate\mappings\Document.hbm.xml
- Configured SessionFactory: null
- Mapping class: ext.als.xcg.mrp.traceability.beans.Document -> DOCUMENT
- Using Hibernate built-in connection pool (not for production use!)
- Hibernate connection pool size: 1
- autocommit mode: false
- using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:wind
- connection properties: {user=mrp, password=****}
- Using dialect: org.hibernate.dialect.Oracle9iDialect
- Could not obtain connection metadata
- Using default transaction strategy (direct JDBC transactions)
- No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
- Automatic flush during beforeCompletion(): disabled
- Automatic session close at end of transaction: disabled
- JDBC batch size: 15
- JDBC batch updates for versioned data: disabled
- Scrollable result sets: enabled
- JDBC3 getGeneratedKeys(): disabled
- Connection release mode: auto
- Default batch fetch size: 1
- Generate SQL with comments: disabled
- Order SQL updates by primary key: disabled
- Order SQL inserts for batching: disabled
- Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
- Using ASTQueryTranslatorFactory
- Query language substitutions: {}
- JPA-QL strict compliance: disabled
- Second-level cache: enabled
- Query cache: disabled
- Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
- Cache provider: org.hibernate.cache.NoCacheProvider
- Optimize cache for minimal puts: disabled
- Structured second-level cache entries: disabled
- Echoing all SQL to stdout
- Statistics: disabled
- Deleted entity synthetic identifier rollback: disabled
- Default entity-mode: pojo
- Named query checking : enabled
- Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Failed to create sessionFactory object.org.hibernate.HibernateException: could not init listeners
Exception in thread "main" java.lang.ExceptionInInitializerError
at ext.als.xcg.mrp.traceability.manager.DocumentManager.main(DocumentManager.java:26)
Caused by: org.hibernate.HibernateException: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:2010)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at ext.als.xcg.mrp.traceability.manager.DocumentManager.main(DocumentManager.java:21)
Caused by: java.lang.ClassCastException: org.hibernate.cfg.Configuration
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:82)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
... 3 more
这是我的源代码和配置文件:
Hibernate.cfg.xml:
<?xml version="1.0"?>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:wind</property>
<property name="connection.username">mrp</property>
<property name="connection.password">mrp</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- to solve java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator error -->
<property name="hibernate.validator.apply_to_ddl">false</property>
<property name="hibernate.validator.autoregister_listeners">false</property>
<property name="hibernate.jdbc.use_get_generated_keys">false</property>
<!-- List of XML mapping files -->
<mapping resource="ext\als\hibernate\mappings\Document.hbm.xml"/>
</session-factory>
我的对象映射
<hibernate-mapping>
此类包含文档详细信息。
</id>
<property name="docNumber" column="DOC_NUMBER" type="string"/>
<property name="docVersion" column="DOC_VERSION" type="string"/>
<property name="xcgFile" column="XCG_FILE" type="string"/>
<property name="xcgDate" column="XCG_DATE" type="date"/>
我的测试类(class):
package ext.als.xcg.mrp.traceability.manager;
import java.util.List;
import java.util.Date;
import java.util.Iterator;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import ext.als.xcg.mrp.traceability.beans.Document;
public class DocumentManager {
private static SessionFactory factory;
public static void main(String[] args) {
try{
factory = new Configuration().configure("ext\\als\\hibernate\\hibernate.cfg.xml").buildSessionFactory();
//factory = new Configuration().configure().buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
DocumentManager DM = new DocumentManager();
/* Add few employee records in database */
Integer docID1 = DM.addDocument("DOC001", "00", "file_1.csv", new Date());
Integer docID2 = DM.addDocument("DOC002", "02", "file_1.csv", new Date());
Integer docID3 = DM.addDocument("DOC003", "05", "file_1.csv", new Date());
/* List down all the employees */
DM.listDocuments();
/* Delete an employee from the database */
DM.deleteDocument(docID2);
/* List down new list of the employees */
DM.listDocuments();
}
/* Method to CREATE an employee in the database */
public Integer addDocument(String docNumber, String docVersion, String xcgFile, Date xcgDate){
Session session = factory.openSession();
Transaction tx = null;
Integer documentID = null;
try{
tx = session.beginTransaction();
Document document = new Document(docNumber, docVersion, xcgFile, xcgDate);
documentID = (Integer) session.save(document);
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
return documentID;
}
/* Method to READ all the documents */
public void listDocuments( ){
Session session = factory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
List documents = session.createQuery("FROM Document").list();
for (Iterator iterator =
documents.iterator(); iterator.hasNext();){
Document document = (Document) iterator.next();
System.out.println("Document Number: " + document.getDocNumber());
System.out.println("Document Version:" + document.getDocVersion());
System.out.println("Xcg File:" + document.getXcgFile());
System.out.println("Xcg Date:" + document.getXcgDate());
}
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
}
/* Method to DELETE an employee from the records */
public void deleteDocument(Integer documentID){
Session session = factory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
Document document =
(Document)session.get(Document.class, documentID);
session.delete(document);
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
}
}
预先感谢您的帮助!朱塞佩
最佳答案
看起来您的 Hibernate 和 Hibernate Search jar 版本不兼容。
您需要使用
Hibernate 3.6.0.Final 为 Hibernate Search 3.3.0.Final
或
Hibernate 3.6.3.Final 为 Hibernate Search 3.4.0.Final
关于java - 无法创建 sessionFactory 对象.org.hibernate.HibernateException : could not init listeners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34791880/
我的一位教授给了我们一些考试练习题,其中一个问题类似于下面(伪代码): a.setColor(blue); b.setColor(red); a = b; b.setColor(purple); b
我似乎经常使用这个测试 if( object && object !== "null" && object !== "undefined" ){ doSomething(); } 在对象上,我
C# Object/object 是值类型还是引用类型? 我检查过它们可以保留引用,但是这个引用不能用于更改对象。 using System; class MyClass { public s
我在通过 AJAX 发送 json 时遇到问题。 var data = [{"name": "Will", "surname": "Smith", "age": "40"},{"name": "Wil
当我尝试访问我的 View 中的对象 {{result}} 时(我从 Express js 服务器发送该对象),它只显示 [object][object]有谁知道如何获取 JSON 格式的值吗? 这是
我有不同类型的数据(可能是字符串、整数......)。这是一个简单的例子: public static void main(String[] args) { before("one"); }
嗨,我是 json 和 javascript 的新手。 我在这个网站找到了使用json数据作为表格的方法。 我很好奇为什么当我尝试使用 json 数据作为表时,我得到 [Object,Object]
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我听别人说 null == object 比 object == null check 例如: void m1(Object obj ) { if(null == obj) // Is thi
Match 对象 提供了对正则表达式匹配的只读属性的访问。 说明 Match 对象只能通过 RegExp 对象的 Execute 方法来创建,该方法实际上返回了 Match 对象的集合。所有的
Class 对象 使用 Class 语句创建的对象。提供了对类的各种事件的访问。 说明 不允许显式地将一个变量声明为 Class 类型。在 VBScript 的上下文中,“类对象”一词指的是用
Folder 对象 提供对文件夹所有属性的访问。 说明 以下代码举例说明如何获得 Folder 对象并查看它的属性: Function ShowDateCreated(f
File 对象 提供对文件的所有属性的访问。 说明 以下代码举例说明如何获得一个 File 对象并查看它的属性: Function ShowDateCreated(fil
Drive 对象 提供对磁盘驱动器或网络共享的属性的访问。 说明 以下代码举例说明如何使用 Drive 对象访问驱动器的属性: Function ShowFreeSpac
FileSystemObject 对象 提供对计算机文件系统的访问。 说明 以下代码举例说明如何使用 FileSystemObject 对象返回一个 TextStream 对象,此对象可以被读
我是 javascript OOP 的新手,我认为这是一个相对基本的问题,但我无法通过搜索网络找到任何帮助。我是否遗漏了什么,或者我只是以错误的方式解决了这个问题? 这是我的示例代码: functio
我可以很容易地创造出很多不同的对象。例如像这样: var myObject = { myFunction: function () { return ""; } };
function Person(fname, lname) { this.fname = fname, this.lname = lname, this.getName = function()
任何人都可以向我解释为什么下面的代码给出 (object, Object) 吗? (console.log(dope) 给出了它应该的内容,但在 JSON.stringify 和 JSON.parse
我正在尝试完成散点图 exercise来自免费代码营。然而,我现在只自己学习了 d3 几个小时,在遵循 lynda.com 的教程后,我一直在尝试确定如何在工具提示中显示特定数据。 This code
我是一名优秀的程序员,十分优秀!