Results 1 to 2 of 2

Thread: test integration for dao in JEE architecture

  1. #1
    Join Date
    May 2011
    Posts
    1

    Question test integration for dao in JEE architecture

    i want to implement a test for the dao classes, but while acting in the same way as in the spring by example (partIII.persistence chapter : Simple Spring Transactional JUnit 4
    Test)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <import resource="classpath:WebContent/WEB-INF/DispatcherServlet-servlet.xml"/>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"
    p:sessionFactory-ref="sessionFactory" />
    <tx:annotation-driven/>
    <bean id="informationDAO" class="ma.lcaMaroc.domain.dao.hibernate3.InformationDAOImp" 
    p:sessionFactory-ref="sessionFactory" />
    </beans>
    the matter is that p:sessionFactory-ref="sessionFactory", because of using the HibernateTemplate instead of SessionFactory.
    so here is the "DispatcherServlet-servlet.xml" file:
    Code:
    <flex:message-broker>
    	<flex:remoting-service default-channels="my-amf"/>
    </flex:message-broker>
    
    <context:annotation-config />
    <context:component-scan base-package="ma.lcaMaroc"/>
    	
    	<bean id="dataSource"
    			class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    			<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    			<property name="url" value="jdbc:mysql://localhost:3306/lcadb"></property>
    			<property name="username" value="root"/>
    			
    	</bean>
    	
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="packagesToScan" value="ma.lcaMaroc" />
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				<prop key="hibernate.hbm2ddl.auto">create</prop>				
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>
    	
    	<!-- ******DAO************DAO************DAO************DAO************DAO************DAO************DAO****** -->
    
    	<bean id="informationDAO" class="ma.lcaMaroc.domain.dao.hibernate3.InformationDAOImp" lazy-init="true">
    		<property name="template" ref="hibernateTemplate" />
    	</bean>

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    And your problem is?!

    some other advices

    1) Don't use HibernateTemplate/HibernateDaoSupport it isn't recommended anymore
    2) You have 2 instances of your dao, don't do that...
    3) You don't need context:annotation-config that is already implied by the component-scan
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •