facebook

HQL editor + multiple Spring configuration

  1. MyEclipse Archived
  2.  > 
  3. Bugs
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #254416 Reply

    antoine
    Member

    Hi,

    I have an hibernate-Spring project on 5.0M2 with two configurations : one for test with a db on MySQL and one for production with Oracle. I created 2 spring configuration sets to switch from test to production and vice versa. Each spring config file contain an hibernate Session factory for each db

    I don’t know if it’s a bug but I’m unable to switch to one configuration to another for the hibernate perspective. The hibernate perspective always load the Oracle configuration. In the property of the project I changed the MyEclipse-Hibernate configuration to point to the Spring config file and sessioFactory for MySQL but it keeps using Oracle config file. The only way I found to switch to test config file is to remove oracle spring configuration file from the spring configuration.

    Of course I don’t have any pb to choose my environnement in my application.

    I don’t know what to send you to help you resolve this or telling me what I’m doing wrong.

    thank you

    #254437 Reply

    Haris Peco
    Member

    Antoine,

    I have tried reproduce your case and make this :

    – make hibernate.cgg.xml (for oracle)
    – hibernatemysql.cfg.xml for MySQL
    and add some mappings

    – make applicationContext.xml which have session factory shoing to oracle cfg.xml
    – applicationContext-mysql.xml for mysql mappings

    add both spring context files in spring config (with or without config sets, it isn’t important)

    – open some hql file (test.hql)

    Now I can :
    – choose MyEclipse-Hibernate property and applicationContext.xml and session factory form this file
    – refresh hql editor and work with oracle

    or
    – choose MyEclipse-Hibernate property and applicationContext-mysql.xml and session factory form this file
    – refresh hql and work with mysql

    When I call Reverse engineering wizard for making mappings MyEclipse use selected hibernate property too

    Can you send more details about your problem , please

    Thanks

    #254441 Reply

    antoine
    Member

    Thanks for your answer,

    I have 3 spring config files.
    – One defining dataSource and Hibernate sessionFactory for MySQL : appCtx4MySQL.xml
    – One defining the same but for Oracle : appCtx4Oracle.xml
    – The third one contains all my applications beans : applicationContext.xml

    If I want to run myWeb app in test I load appCtx4MySQL.xml and ApplicationContext.xml in my web.xml. If I want to switch to production DB I load appCtx4Oracle.xml and ApplicationContext.xml in web.xml.

    Here is appCtx4MySQL

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
        <!-- ========================= Start of PERSISTENCE DEFINITIONS =========================
        -->
        
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="url">
                <value>jdbc:mysql://localhost:3306/CVPR</value>
            </property>
            <property name="username">
                <value>login</value>
            </property>
            <property name="password">
                <value>password</value>
            </property>
        </bean>
    
    
        <!-- Hibernate SessionFactory Definition -->
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">
                        org.hibernate.dialect.MySQLDialect
                    </prop>
                </props>
            </property>
            <property name="lobHandler">
            <ref bean="MySQLLobHandler"/>
            </property>
            <property name="mappingResources">
                <list>
                    <value>edu/essec/cv/prof/domain/Cv.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Person.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Resource.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/declarations/Declaration.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/OrgUnit.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Theme.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Revue.hbm.xml</value>                
                </list>
            </property>
        </bean>
    
    <bean id="MySQLLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
           
    
    </beans>

    Here is appCtx4Oracle.xml (same beans id as MySQL but oracle drivers and dialect :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    
    
    <beans>
    
        <!-- ========================= Start of PERSISTENCE DEFINITIONS =========================
        -->
    
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName">
                <value>oracle.jdbc.driver.OracleDriver</value>
            </property>
            <property name="url">
                <value>jdbc:oracle:thin:@server:1521:cvpr</value>
            </property>
            <property name="username">
                <value>login</value>
            </property>
            <property name="password">
                <value>password</value>
            </property>
        </bean>
    
        <!-- Hibernate SessionFactory Definition -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                </props>
            </property>
    
            <property name="lobHandler">
            <ref bean="oracleLobHandler"/>
            </property>
    
            <property name="mappingResources">
                <list>
                    <value>edu/essec/cv/prof/domain/Cv.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Person.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Resource.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/declarations/Declaration.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/OrgUnit.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Theme.hbm.xml</value>
                    <value>edu/essec/cv/prof/domain/Revue.hbm.xml</value>
                </list>
            </property>
        </bean>
    
    <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
    </beans>

    Here is the begining of my ApplicationContext

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    
        <!-- Spring Data Access Exception Translator Defintion -->
        <bean id="jdbcExceptionTranslator"
            class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
        </bean>
    
        <!-- Hibernate Template Defintion -->
        <bean id="hibernateTemplate"
            class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
            <property name="jdbcExceptionTranslator">
                <ref bean="jdbcExceptionTranslator" />
            </property>
        </bean>
        <!-- Hibernate Transaction Manager Definition -->
        <bean id="transactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
        </bean>
    ...

    When I go to MyEclipse-Hibernate properties, I can switch to appCtx4MySQL.xml and sessionFactory or appCtx4Oracle.xml and sessionFactory but HQL editor always use Oracle configuration.

    Thanks for your help on this

    Antoine

    #254446 Reply

    Haris Peco
    Member

    Antoine,

    I can reproduce your case when I use same name for session factory in both application contexts (in my example hql use MySQL always 🙂 ).It’s because MyEclipse use complete configuration and grab first session
    Workaround is simple : when you want use MySQL remove oracle’s application context from spring configuration complete and reverse.
    I will see if we can make that you can use config sets (no complete spring configuration) anyhow

    Best regards

    #254491 Reply

    antoine
    Member

    That’s what I already do.

    thanks for your information on the subject

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: HQL editor + multiple Spring configuration

You must be logged in to post in the forum log in