Announcement Announcement Module
Collapse
No announcement yet.
spring hibernate and axis Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring hibernate and axis

    Hi,

    I have two modules in my application.
    The first one is a webservice. (Axis 1.1, spring 1.1.3 and Hibernate 2.1.6 ) This web service is responsible for
    accessing the database.

    The second one is web application which is consuming this web service. It does not do anything other than presentation.

    The problem I am facing now is, when I request Hibernate for records in one table, it is executing so many queries.
    It is fetching records from the tables which have foreign-key relation with that table. So when the web application is
    using this web service, it is taking lot of time to load the page. ( 20 minutes just to display 5-6 records!!!!). I think this is because Axis is trying to (De)serialize all the objects that are retrieved from the database.

    I tried keeping lazy="true" for all the associations. but by the time, the web appliction is accessing those associations, the session is getting closed causing "session closed exception" . but i am not opening or closing any sessions explicitly..spring is doint that for me. i do not want to tak any control on the sessions and i want to leave that to spring...

    I know that this is a very common requirement and i am missing some basic thing...plz help as performance of my application is really very poor and unacceptable.

    Following is my applicationContext.xml. i removed all the unwanted entries..

    Code:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC 
    "-//SPRING//DTD BEAN//EN"
    "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName">
    			<value>$&#123;hibernate.connection.driver_class&#125;</value>
    		</property>
    		<property name="url">
    			<value>$&#123;hibernate.connection.url&#125;</value>
    		</property>
    		<property name="username">
    			<value>$&#123;hibernate.connection.username&#125;</value>
    		</property>
    		<property name="password">
    			<value>$&#123;hibernate.connection.password&#125;</value>
    		</property>
    
    	</bean>
    
    	<!-- Hibernate SessionFactory -->
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource" />
    		</property>
    
    		<property name="mappingResources">
    			<list>
    				<value>
    					com/sat/impl/MyWebService.hbm.xml
    				</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					$&#123;hibernate.dialect&#125;
    				</prop>
    			</props>
    		</property>
    
    	</bean>
    
    	<!-- Transaction manager for a single Hibernate SessionFactory &#40;alternative to JTA&#41; -->
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    
    	<!-- Add DAOs here -->
    	<bean id="roleDao"
    		class="com.sat.dao.hibernate.HibernateRoleDAO">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    
    	<bean id="ProductionService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref local="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="userManagerTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="remove*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="userManagerTarget"
    		class="com.sat.ProductionServiceImpl">
    		<property name="roleDao">
    			<ref local="roleDao" />
    		</property>
    	</bean>
    </beans>
    Thanks,
    SSSS.

  • #2
    Try following Karl Baum's example

    http://www.jroller.com/page/kbaum/20040708

    Give that a shot.

    Comment


    • #3
      I am having the same probelem

      The link provide no longer contains the info. Has anyone founf a fix for this problem?

      Comment


      • #4
        You'll always have issues in regards to lazy loading and trying to work on the object graph after a proxied method has returned (especially when trying to rewrap your objects into something a bit more usable for web services)


        On your web service methods, the easiest way is to programatically define the transaction boundary, so that your transactional proxied object will join it.

        for example, let's say you have a method caled "getFoo()" in your webservice implementation

        Code:
               ....
        
               public SomeResult getFoo() {
        
                    SomeResult someResult = null;
        
                     PlatformTransactionManager transManager = applicationContext.getBean("transactionManager");
        
                     DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        
                     def
        				.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        
        		TransactionStatus status = transactionManager.getTransaction(def);
        
        
                     try {
        
                             // call your business objects here
        
                            // any code in here won't have any problems with lazy loading.
        
                             // remap to your result here
        
                             someResult = ....
        
                             transManager.commit(status);
        
                     } catch (Throwable error) {
        
                             transManager.rollback(status);          
        
                     }
        
                    return result;
        
               }
        Or you can create a facade, wrap it up in a transaction declaratively and just make sure you are doing all your re-wrapping inside said method.

        Comment

        Working...
        X