-->
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.  [ 4 posts ] 
Author Message
 Post subject: Why I must to add at least a mapping in hibernate.cfg.xml?
PostPosted: Thu Aug 12, 2004 1:39 pm 
Newbie

Joined: Thu Aug 12, 2004 1:14 pm
Posts: 2
I need to add mappings in runtime because, at build time, i don't known wich classes are going to be mapped.
In the definition of hibernate config files (hibernate-configuration-2.0.dtd), the element session-factory is defined as follow :

<!ELEMENT session-factory (property*, mapping+, (class-cache|collection-cache|jcs-class-cache|jcs-collection-cache)*)>

That means that you must to have at least one mapping in your config file. Why this is needed? Why don't you can initialize HIbernate without any mapping and then add it to the configuration?
I've replaced mapping+ by a mapping* in the DTD and everything works fine.
Thank you

Hibernate version: 2.1.4

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- datasource connection properties -->
<property name="connection.datasource">myDS</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

<!-- dialect for Oracle 9 -->
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
</session-factory>
</hibernate-configuration>

Full stack trace of any exception that occurs:
ERROR Configuration: problem parsing configuration/hibernate.cfg.xml
org.dom4j.DocumentException: Error on line 37 of document : Element session-factory not complete, expected elements '[property, mapping]'. Nested exception: Element session-factory not complete, expected elements '[property, mapping]'.
at org.dom4j.io.SAXReader.read(SAXReader.java:355)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:930)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860)
at com.siderar.nca.core.hibernate.HibernateHelper.loadConfig(HibernateHelper.java:116)
at com.siderar.nca.core.hibernate.HibernateHelper.init(HibernateHelper.java:56)
at com.siderar.nca.core.hibernate.HibernateHelper.getSessionFactory(HibernateHelper.java:137)
at com.siderar.nca.core.hibernate.HibernateHelper.currentSession(HibernateHelper.java:80)
at com.siderar.nca.core.transaction.TransactionManager.initHibernateContext(TransactionManager.java:165)
at com.siderar.nca.core.transaction.TransactionManager.beginTransaction(TransactionManager.java:60)
at com.siderar.nca.core.systemevent.SystemEvent.execute(SystemEvent.java:170)
at com.siderar.nca.core.frontcontroller.FrontController.execute(FrontController.java:135)
at com.siderar.nca.core.utils.TestUtility.execute(TestUtility.java:124)
at com.siderar.nca.producto.module.FacturaItemModuleTest.testAltaFacturaAndDept(FacturaItemModuleTest.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Nested exception:
oracle.xml.parser.v2.XMLParseException: Element session-factory not complete, expected elements '[property, mapping]'.
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:205)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:270)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:147)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:930)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860)
at com.siderar.nca.core.hibernate.HibernateHelper.loadConfig(HibernateHelper.java:116)
at com.siderar.nca.core.hibernate.HibernateHelper.init(HibernateHelper.java:56)
at com.siderar.nca.core.hibernate.HibernateHelper.getSessionFactory(HibernateHelper.java:137)
at com.siderar.nca.core.hibernate.HibernateHelper.currentSession(HibernateHelper.java:80)
at com.siderar.nca.core.transaction.TransactionManager.initHibernateContext(TransactionManager.java:165)
at com.siderar.nca.core.transaction.TransactionManager.beginTransaction(TransactionManager.java:60)
at com.siderar.nca.core.systemevent.SystemEvent.execute(SystemEvent.java:170)
at com.siderar.nca.core.frontcontroller.FrontController.execute(FrontController.java:135)
at com.siderar.nca.core.utils.TestUtility.execute(TestUtility.java:124)
at com.siderar.nca.producto.module.FacturaItemModuleTest.testAltaFacturaAndDept(FacturaItemModuleTest.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)


Name and version of the database you are using:Oracle9


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 1:58 pm 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
I assume your database is not created at runtime.

Therefore you already know which tables you have.

Which classes map to those tables?

<i>Those</i> are the classes you should specify in the config file.

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 2:27 pm 
Newbie

Joined: Thu Aug 12, 2004 1:14 pm
Posts: 2
dplass wrote:
I assume your database is not created at runtime.

Therefore you already know which tables you have.

Which classes map to those tables?

<i>Those</i> are the classes you should specify in the config file.


I'm building the infrastructure of a big system with many bussiness subsystems in it. Each subsystem has its own database schema and runs in its own container, but all of them uses my infrastructure. I want to do some settings (common to all the subsystems) in hibernate config, but each subsystem has its own tables and classes, so, at build time, i don't know wich are my client's tables and classes, so i can't map them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 2:29 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You could also load the hibernate.cfg.xml into a DOM, add your class mapping entrys and feed this into

Code:
Configuration.configure(org.w3c.dom.Document document)


On the other hand: It seams that the Configuration class can happyly be first initialized without a class mapping in the hibernate.cfg.xml and get the mappings later with one of the various add methods. So this is maybe a bug in the current DTD?

HTH
Ernst


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.