-->
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.  [ 1 post ] 
Author Message
 Post subject: Anwendung für verschiedene Datenquelle(DBs) ???
PostPosted: Fri Oct 09, 2009 9:30 am 
Newbie

Joined: Tue Sep 29, 2009 5:02 am
Posts: 8
Hallo Zusammen!

ich versuche eine Anwendung die für verschiedene Datenquelle(DBs) ausgelegt ist,
mit Hibernate zu unterstützen. Die Datenstruktur ist identisch.

Es scheitert aber daran, dass Hibernate immer
genau auf eine namentliche DB festlegt.
Also eine xxx.hibernate.cfg.xml
durch yyy.hibernate.cfg.xml ersetzen, reicht nicht aus (s.unten)

da in den iii.hbm.xml der catalog "db_start" hinterlegt ist....

Code:
....
protected static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
           SessionFactory sf = null;
           System.out.println("DBHandler.url " + DBHandler.url);
           
           Configuration cfg = new Configuration();
           
           
             
           if (DBHandler.url.equals("jdbc:mysql://10.100.1.10/test")){
              cfg.configure("/test.hibernate.cfg.xml");
                 
           
              cfg.buildSettings();
           } else if (DBHandler.url.equals("jdbc:mysql://10.100.1.10:3306/work")){
              cfg.configure("/work.hibernate.cfg.xml");
           else {
              cfg.configure();
           }
       
            return cfg.buildSessionFactory();
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }

....
    }


Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_clas">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">pw123</property>
        <property name="hibernate.connection.url">jdbc:mysql://10.100.1.10:3306/db_start</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <mapping resource="de/wantech/mda/ZahlungBelegkopf.hbm.xml" />
        <mapping resource="de/wantech/mda/ReportVerleihStatistik.hbm.xml" />
.....





Gibt es ein adequate Lösung ohne für jede DB die einzelnen hbm zu generieren,
und die Anwendung für alle DBs speziell zusammenzubauen???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.