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 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://" />
  <property name="username" value="doolloop2" />
  <property name="password" value="doolloop" />

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
     <property name="mappingLocations">
    <property name="hibernateProperties">
  <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
  <prop key="hibernate.show_sql">true</prop> 
  <prop key="hibernate.hbm2ddl.auto">update</prop> 
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />

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 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