-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using Spring's context file for Hibernate
PostPosted: Fri May 26, 2006 1:45 pm 
Beginner
Beginner

Joined: Tue Mar 23, 2004 8:40 pm
Posts: 22
I have all my Hibernate settings within a Spring file (i.e. applicationContext-hibernate.xml) instead of hibernate.cfg.xml, how can I refer to the Hibernate settings for the Hibernate Tools (e.g. Ant Task "hibernatetool" and Eclipse plugin) to work?

Code:
<!--
applicationContext-hibernate.xml
-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!-- jdbc information is defined in jdbc.properties -->
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
   
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
       
        <property name="mappingResources">
            <list>
                <value>com/microsoft/model/User.hbm.xml</value>
                <value>com/microsoft/model/Department.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.generate_statistics">false</prop>
                <prop key="use_reflection_optimizer">false</prop>               
             </props>
        </property>
     </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <bean id="userDAO" class="com.microsoft.dao.hibernate.UserDAOHibernate">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <bean id="departmentDAO" class="com.microsoft.dao.hibernate.DepartmentDAOHibernate">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

</beans>


Thanks in advance.

Martin


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
That would require the tools to be dependent on Spring....not really optimal plus your setup there is dependent on a datasource which is most likely not available via ant nor eclipse.

So in short it is not supported out of the box and don't know why you just don't use hibernate.cfg.xml since your are not doing anything in that spring setup that hibernate.cfg.xml doesn't handle (hibernate configuration wise that is)

...but i guess we could allow for some generic <generic-configuration> element that could handle this.....how do you get a Configuration from this file *without* creating a SessionFactory ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Using Spring's context file for Hibernate
PostPosted: Sat May 27, 2006 11:57 am 
Newbie

Joined: Mon Jul 25, 2005 11:30 am
Posts: 4
Or you could leave the hibernate configuration in hibernate.cfg.xml and use the configLocation property of the LocalSessionFactoryBean. That way you'd just have one configuration that you can use for both, only that it's not in the applicationContext.xml file.

hth,

Lutz


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 27, 2006 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
exactly...

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.