Results 1 to 4 of 4

Thread: spring hibernate and axis

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    7

    Default 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. #2
    Join Date
    Feb 2005
    Posts
    217

    Default Try following Karl Baum's example


  3. #3

    Default I am having the same probelem

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

  4. #4
    Join Date
    Mar 2006
    Posts
    17

    Default

    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.

Similar Threads

  1. AXIS web-service - ServletEndpointSupport
    By r0bh in forum Remoting
    Replies: 9
    Last Post: Jun 3rd, 2008, 04:42 AM
  2. spring + hibernate + webservice
    By pflanzenmoerder in forum Remoting
    Replies: 0
    Last Post: Sep 24th, 2005, 03:44 PM
  3. Hibernate Axis OpenSessionViewFilter problem
    By ByronSpringBean in forum Data
    Replies: 0
    Last Post: Jul 22nd, 2005, 01:03 PM
  4. Sping, Hibernate, and XML marshalling
    By alecswan in forum Architecture
    Replies: 0
    Last Post: Apr 10th, 2005, 11:25 AM
  5. Replies: 0
    Last Post: Apr 6th, 2005, 07:42 AM

Posting Permissions

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