• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

using multiple datasources in hibernate app

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application I will be using 3 different datasources.
How do I configure that ?
I'm trying to use
public SessionFactory createSessionFactory() {
Configuration config = new Configuration();
return config.buildSessionFactory();

SessionFactory sessionFactory = createSessionFactory();
Session sess = sessionFactory.openSession();
Query query = sess.getNamedQuery("loadEvent");
List result = query.list();

But it is not working
srija patel
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My cfg file is like this
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<!-- Database connection settings -->
<property name="show_sql">true</property>
<property name="connection.username">root</property>
<property name="connection.password">sess</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="events/Event.hbm.xml"/>

hbm file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="events.Event" table="EVENT">
<id name="id" column="EVENT_ID">
<generator class="native"/>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
<query name="loadEvent">select ev from Event ev</query>
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you define (in cfg file):
<mapping resource="events/Event.hbm.xml"/>

Do you still have to define:
config.addResource("events/Event.hbm.xml"); ? in your java file.

If it still doesn't work, can you paste the error also. It might ease to answer.

I think I'll just lie down here for a second. And ponder this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic