These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Configuration File Not Found!
PostPosted: Thu Jan 17, 2008 7:13 am 
Newbie

Joined: Mon Jan 08, 2007 6:25 am
Posts: 6
Hi All,

I'm using the latest Hibernate library (aka v3) for my latest project, and i'm keep receiving this error when ever i run my basic tests.

Code:
org.hibernate.HibernateException: Could not parse configuration:
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.initialize(_BaseRootDAO.java:104)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.getSessionFactory(_BaseRootDAO.java:145)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.getSession(_BaseRootDAO.java:64)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.getSession(_BaseRootDAO.java:42)
   at com.wrenhill.backend.db.dao.base._BaseRootDAO.findAll(_BaseRootDAO.java:259)
   at com.wrenhill.backend.db.dao.base.BaseCompetitionDAO.findAll(BaseCompetitionDAO.java:82)
   at unit.com.wrenhill.backend.db.TestCompetitionDao.testGetAll(TestCompetitionDao.java:22)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
   at org.dom4j.io.SAXReader.read(SAXReader.java:482)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
   ... 31 more



The hibernate.cfg.xml file is found under my /src folder which as the name states is my source folder.

The rest of the java files are found as shown below:

+ src
|
|+com
| |
| |+backend
| | |
| | |+db
| | | |
| | | |+mappings (all my mapping files are here)
| | | |+dao (All dao and interfaces are here)
| | | |
-hibernate.cfg.xml
-logging.conf

Do i have a wrong structure or what?

Just in case below is my current configuration file:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
       
<hibernate-configuration>
   <session-factory>
      <!-- local connection properties -->
      <property name="hibernate.connection.url">
         jdbc:mysql://localhost/db1_test
      </property>
      <property name="hibernate.connection.driver_class">
         com.mysql.jdbc.Driver
      </property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">gandalF13</property>
      <!-- property name="hibernate.connection.pool_size"></property -->
      <!-- dialect for MySQL -->
      <property name="dialect">
         org.hibernate.dialect.MySQLDialect
      </property>
      <property name="hibernate.show_sql">false</property>
      <property name="hibernate.transaction.factory_class">
         org.hibernate.transaction.JDBCTransactionFactory
      </property>
      
      <mapping resource="com/backend/db/mappings/Country.hbm.xml" />
      <mapping resource="com/backend/db/mappings/Fixture.hbm.xml" />
      <mapping resource="com/backend/db/mappings/Sport.hbm.xml" />
      <mapping resource="com/backend/db/mappings/Team.hbm.xml" />
      <mapping
   </session-factory>
</hibernate-configuration>


Thanks all for your time..

Regards
NF


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:23 am 
Newbie

Joined: Fri Jan 11, 2008 5:50 am
Posts: 9
Hi NF,

It could be just a copy/paste error when you posted the topic, but it looks to be the 3rd to last line in your config file:

Code:
<mapping


Delete that and you should be on your way.

Hope this helps

Andy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:35 am 
Newbie

Joined: Mon Jan 08, 2007 6:25 am
Posts: 6
Sorry about that...i delete some of the mappings because it would have been to cumbersome..so that is just a typo....thanks anyways...

NF


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:55 am 
Newbie

Joined: Fri Jan 11, 2008 5:50 am
Posts: 9
No worries, it might be worth checking the symantics of your XML, I've had some really mysterious errors when parsing the hibernate XML file.

When you build your app where is hibernate.cfg.xml copied to? It should reside at the top level of whereever your classes reside.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 9:41 am 
Newbie

Joined: Mon Jan 08, 2007 6:25 am
Posts: 6
Hi Again,

well i finally solved that piece of the puzzle..i had create an invalid Session Factory..so know the test is running until i go this error:

Code:
org.hibernate.HibernateException: No CurrentSessionContext configured!
   at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
   at unit.com.wrenhill.backend.dao.TestCompDao.testDao(TestCompDao.java:24)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
   at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
   at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
   at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



The following error is returned from log4j

Code:

14:40:04,828  INFO Environment:514 - Hibernate 3.2.5
14:40:04,828  INFO Environment:547 - hibernate.properties not found
14:40:04,828  INFO Environment:681 - Bytecode provider name : cglib
14:40:04,843  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
14:40:04,921  INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
14:40:04,921  INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
14:40:05,031  INFO Configuration:1541 - Configured SessionFactory: null
14:40:05,031  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
14:40:05,031  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
14:40:05,031  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
14:40:05,046  INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/iscore_test
14:40:05,046  INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
14:40:05,375  INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.45-community-nt
14:40:05,375  INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
14:40:05,390  INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLDialect
14:40:05,453  INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
14:40:05,453  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
14:40:05,453  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
14:40:05,453  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
14:40:05,453  INFO SettingsFactory:154 - JDBC batch size: 15
14:40:05,453  INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
14:40:05,453  INFO SettingsFactory:162 - Scrollable result sets: enabled
14:40:05,453  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
14:40:05,453  INFO SettingsFactory:178 - Connection release mode: auto
14:40:05,453  INFO SettingsFactory:202 - Maximum outer join fetch depth: 2
14:40:05,453  INFO SettingsFactory:205 - Default batch fetch size: 1
14:40:05,468  INFO SettingsFactory:209 - Generate SQL with comments: disabled
14:40:05,468  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
14:40:05,468  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
14:40:05,468  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:40:05,468  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
14:40:05,468  INFO SettingsFactory:225 - Query language substitutions: {}
14:40:05,468  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
14:40:05,468  INFO SettingsFactory:235 - Second-level cache: enabled
14:40:05,468  INFO SettingsFactory:239 - Query cache: disabled
14:40:05,468  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
14:40:05,468  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
14:40:05,468  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
14:40:05,484  INFO SettingsFactory:283 - Echoing all SQL to stdout
14:40:05,484  INFO SettingsFactory:290 - Statistics: disabled
14:40:05,484  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
14:40:05,484  INFO SettingsFactory:309 - Default entity-mode: pojo
14:40:05,484  INFO SettingsFactory:313 - Named query checking : enabled
14:40:05,531  INFO SessionFactoryImpl:161 - building session factory
14:40:05,531  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured



I'm not using jndi nor using jboss..i'm directly accessing MySql!!

Any reasons why?

Thanks once again
NF


Top
 Profile  
 
 Post subject: jndi message
PostPosted: Mon Feb 23, 2009 10:11 pm 
Beginner
Beginner

Joined: Tue Oct 28, 2008 6:41 pm
Posts: 20
Hi,
Try including the following two lines in your hibernate.cfg.xml file.

<session-factory name="java:hibernate/SessionFactory">
<property name="hibernate.session_factory_name">SessionFactory</property>

hibernate needs a session factory to connect. It makes sense that it needs a handle/name to that factory .

I connect like this
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext()
.lookup("SessionFactory");

} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException(
"Could not locate SessionFactory in JNDI");
}
}

an alternate way if you are not using jndi is :

sessionFactory = new Configuration().configure().buildSessionFactory();

but you will probably still need

<property name="hibernate.session_factory_name">SessionFactory</property>

in your config file.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.