Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "Failed to create sessionFactory object.org.hibernate.HibernateException: could not init listeners"
- - 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: extalshibernatehibernate.cfg.xml
- - Configuration resource: extalshibernatehibernate.cfg.xml
- - Reading mappings from resource : extalshibernatemappingsDocument.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
- <?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="extalshibernatemappingsDocument.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"/>
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement