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.
|