-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to define 2 data source in hibernate.cfg.xml file?
PostPosted: Fri Dec 01, 2006 4:58 am 
Newbie

Joined: Fri Dec 01, 2006 4:28 am
Posts: 6
Currently my project required me to retrieve data from one database, and manipulate(insert, delete, update) data to another database. How can i define 2 data source in hibernate.cfg.xml file? or any ways to do it?



<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=EVENTS</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<mapping resource="de/gloegl/road2hibernate/Event.hbm.xml"/>
</session-factory>


<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
</session-factory>
</hibernate-configuration>



And the error are:

ERROR - Error parsing XML: /hibernate.cfg.xml(29) Element "hibernate-configuration" does not allow "session-factory" here.
ERROR - problem parsing configuration/hibernate.cfg.xml
org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1287)
Initial SessionFactory creation failed.org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
java.lang.ExceptionInInitializerError
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at de.gloegl.road2hibernate.HibernateAction.add(HibernateAction.java:36)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:25)
Caused by: org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1291)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1287)
... 5 more
Caused by: org.xml.sax.SAXParseException: Element "hibernate-configuration" does not allow "session-factory" here.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3210)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
at de.gloegl.road2hibernate.HibernateAction.add(HibernateAction.java:36)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:25)
Caused by: org.xml.sax.SAXParseException: Element "hibernate-configuration" does not allow "session-factory" here.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3210)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1362)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1824)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1552)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:534)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:318)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1362)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1824)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1552)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:534)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:318)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 5 more
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 5 more
Exception in thread "main"
Java Result: 1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:19 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
You need to define two different session-factories, with differente name:

<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory
name="java:hibernate/SessionFactory1">

...

<session-factory
name="java:hibernate/SessionFactory2">
...

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:49 am 
Newbie

Joined: Fri Dec 01, 2006 4:28 am
Posts: 6
Hi Andresgr, still the same error occurs:-


ERROR - Error parsing XML: /hibernate.cfg.xml(29) Element "hibernate-configuration" does not allow "session-factory" here.
ERROR - problem parsing configuration/hibernate.cfg.xml
org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1287)
Initial SessionFactory creation failed.org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
java.lang.ExceptionInInitializerError
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at de.gloegl.road2hibernate.HibernateAction.search(HibernateAction.java:91)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:30)
Caused by: org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1291)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1287)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
at de.gloegl.road2hibernate.HibernateAction.search(HibernateAction.java:91)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:30)
Caused by: org.xml.sax.SAXParseException: Element "hibernate-configuration" does not allow "session-factory" here.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3210)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
... 5 more
Caused by: org.xml.sax.SAXParseException: Element "hibernate-configuration" does not allow "session-factory" here.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3210)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1362)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1824)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1552)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:534)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:318)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 5 more
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1362)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1824)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1552)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:534)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:318)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 5 more
Exception in thread "main"
Java Result: 1



Any clue how to resolve it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:56 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Ok, try them using two different hibernate configuration files, and create two different Configuration objects accordingly, getting then two different SessionFactory's

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:57 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
From the hibernate doc:

You can pick a different XML configuration file using

SessionFactory sf = new Configuration()
.configure("/my/package/catdb.cfg.xml")
.buildSessionFactory();

_________________
andresgr (--don't forget to rate)


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