Home Get Dialect within some class inside Spring MVC + Hibernate application
Reply: 1

Get Dialect within some class inside Spring MVC + Hibernate application

danny.lesnik
1#
danny.lesnik Published in 2010-12-02 22:20:03Z

I have Hibernate Transaction manager configured inside Spring MVC controller.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="org.postgresql.Driver" />
  <property name="url" value="jdbc:postgresql://127.0.0.1/doolloop2" />
  <property name="username" value="doolloop2" />
  <property name="password" value="doolloop" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
     <property name="mappingLocations">
      <list>
        <value>WEB-INF/mapping/User.hbm.xml</value>
      </list>
    </property>
    <property name="hibernateProperties">
 <props>
  <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
  <prop key="hibernate.show_sql">true</prop> 
  <prop key="hibernate.hbm2ddl.auto">update</prop> 
  </props>
  </property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>   

In Addition, I have some class which needs to get Hibernate Dialect inside on of it method. Is class is not Configured as bean inside Spring Framework.

How can I access Hibernate Dialect property from this class? I believe it should be some static class,but I don't know how can I do it. Please help.

digitaljoel
2#
digitaljoel Reply to 2010-12-02 22:31:14Z

You could separate the properties from the spring config. Put them in a properties file, then reference that in a PropertyPlaceholderConfigurer bean ( http://almaer.com/blog/spring-propertyplaceholderconfigurer-a-nice-clean-way-to-share ). Then you could inject that value into whatever bean it is that you need the value in the same way you are injecting it into the sessionFactory bean.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.297415 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO