-->
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: using more than one data source
PostPosted: Mon Nov 06, 2006 3:58 am 
Newbie

Joined: Mon Nov 06, 2006 3:43 am
Posts: 6
If we need to have more than one data source, what is the best way to handle?
Either by giving one more <session-factory> or by having one more hibernate.cfg.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 5:21 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Use another SessionFactory for another DataSource / Database

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 7:00 am 
Newbie

Joined: Mon Nov 06, 2006 3:43 am
Posts: 6
Can u give some details what is the advantges if i am using one more session Factory istead of using another hibernate.cfg.xml file for another jdbc connection


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 7:01 am 
Newbie

Joined: Mon Nov 06, 2006 3:43 am
Posts: 6
Can u give some more details ,what is the advantge if i am using one more session Factory istead of using another hibernate.cfg.xml file for another jdbc connection


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 7:12 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Well, usually a SessionFactory is configured for one database.

Ramping up a SessionFactory can be a pretty expensive task in terms of the time it takes to ramp it up.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 11:03 pm 
Newbie

Joined: Fri Dec 01, 2006 4:28 am
Posts: 6
Hi Mike,

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

What is the better way to do it? Create another .cfg.xml file or create another <session-factory> within a same file?

Thanks.


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.