Skip to content

Instantly share code, notes, and snippets.

@IanDarwin
Created February 3, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanDarwin/d17fd44d0cc99f14cce16f4d14cc9730 to your computer and use it in GitHub Desktop.
Save IanDarwin/d17fd44d0cc99f14cce16f4d14cc9730 to your computer and use it in GitHub Desktop.
Spring ApplicationContext that includes Hibernate config, saving one file
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:javaee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
<javaee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/lhbooks"/>
<!-- This obviates the need for a hibernate.cfg.xml -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>entity/entity.hbm.xml</value>
<value>orderproc/orderproc.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>
<bean id="personDAO" class="dao.PersonDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="productDAO" class="dao.ProductDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="publisherDAO" class="dao.PublisherDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="anecdoteDAO" class="dao.AnecdotesHome">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment