Results 1 to 6 of 6

Thread: An error terminate at getHibernateTemplate()

  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Default An error terminate at getHibernateTemplate()

    Hi, i had a problem with Hibernate. I have this code in DAOHIBERNATE:

    public Flight selectFlight(String city) {
    Flight flight = null;

    List result = getHibernateTemplate().find("from flight where origin_city=?", city); getHibernateTemplate().flush();

    Iterator iter = result.iterator();
    while(iter.hasNext()){
    flight=(Flight)iter.next();
    System.out.println(flight);
    }

    return flight;

    }

    Whenever i step over the hightlighted red line, an error will occured. They didnt prompt me exception but it println out my error msg in the console.

    Can anybody help me with it? Why it cant execute the line? Is there anything done with configuration? I have this for my hibernate:

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref bean="myDataSource"/>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="show_sql">true</prop>
    <prop key="hibernate.transaction.factory_class">
    org.hibernate.transaction.JDBCTransactionFactory
    </prop>
    <prop key="hibernate.generate_statistics">true</prop>
    </props>

    </property>

    <bean id="profileDao" class="com.trytry.dao.hibernate.ProfileDaoHibernat e">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate"/>
    </property>
    </bean>

    This method in Action class invoke the selectFlight() from DAOHIBERNATE:

    Flight returnedProfile = null;
    System.out.println("Access database HERE...");
    try{
    returnedProfile = t.selectFlight(new String(request.getParameter("origin_city")));
    System.out.println("ReturnedProfile::"+returnedPro file);
    }catch(Exception e){
    errors.add("returnedResult_viewProfileAction", new ActionError("error.returnedResult"));
    }
    if (!errors.isEmpty()) {
    saveErrors(request, errors);
    System.out.println("Errors occur... terminate here");
    forward = mapping.findForward("fail");
    } else {
    request.setAttribute("msg","Profile inserted successfully!" );
    request.setAttribute("profile", flight);
    forward = mapping.findForward("success");
    }
    return (forward);
    }



    Regards,
    tiffany

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Can you put code in [ code] [ /code] tags to make it readable. Can we also see the stacktrace your getting, otherwise its hard to know what the problem is.

  3. #3
    Join Date
    Jan 2007
    Posts
    3

    Default

    Hi karldmoore,

    The error message is "java.util.AbstractList$Itr@110f98f" after i had step over to highlighted red line. This method will put in DAOHIBERNATE and it extends HibernateDaoSupport:

    Code:
    public Flight selectFlight(String city) { 
    Flight flight = null; 
    
    List result = getHibernateTemplate().find("from flight where origin_city=?", city); getHibernateTemplate().flush(); 
    
    Iterator iter = result.iterator(); 
    while(iter.hasNext()){ 
    flight=(Flight)iter.next(); 
    System.out.println(flight); 
    } 
    
    return flight; 
    
    }

    Why it cant execute the line? Is there anything done with configuration?

    This method in Action class invoke the selectFlight() from DAOHIBERNATE:

    Code:
    Flight returnedProfile = null; 
    System.out.println("Access database HERE..."); 
    try{ 
    returnedProfile = t.selectFlight(new String(request.getParameter("origin_city"))); 
    System.out.println("ReturnedProfile::"+returnedPro file); 
    }catch(Exception e){ 
    errors.add("returnedResult_viewProfileAction", new ActionError("error.returnedResult")); 
    } 
    if (!errors.isEmpty()) { 
    saveErrors(request, errors); 
    System.out.println("Errors occur... terminate here"); 
    forward = mapping.findForward("fail"); 
    } else { 
    request.setAttribute("msg","Profile inserted successfully!" ); 
    request.setAttribute("profile", flight); 
    forward = mapping.findForward("success"); 
    } 
    return (forward); 
    }

    I have this for my hibernate:
    Code:
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate"> 
    <property name="sessionFactory"> 
    <ref bean="sessionFactory"/> 
    </property> 
    </bean> 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean"> 
    <property name="dataSource"> 
    <ref bean="myDataSource"/> 
    </property> 
    <property name="hibernateProperties"> 
    <props> 
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop> 
    <prop key="show_sql">true</prop> 
    <prop key="hibernate.transaction.factory_class"> 
    org.hibernate.transaction.JDBCTransactionFactory 
    </prop> 
    <prop key="hibernate.generate_statistics">true</prop> 
    </props> 
    
    </property> 
    
    <bean id="profileDao" class="com.trytry.dao.hibernate.ProfileDaoHibernat e"> 
    <property name="hibernateTemplate"> 
    <ref bean="hibernateTemplate"/> 
    </property> 
    </bean>
    This is my spring-config.xml:

    Code:
    <beans>
    
    
    	<bean id="flight" class="com.trytry.model.Flight"/>
    
    	<bean name="/searchAction" class="com.trytry.actions.FlightAction">
    		<property name="flight">
    			<ref bean="flight"/>
    		</property>
    	</bean>  
    	
    	
    </beans>
    Thank,

    tiffany
    Last edited by chiatai; Jan 6th, 2007 at 01:52 AM.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is that all there is? There that doesn't seem to be much of an error message. I would write a little test case to run this and see what errors you get out of that. Its really hard to solve a problem not knowing what it is.

  5. #5
    Join Date
    Jan 2007
    Posts
    3

    Default

    yeah...i have search the error over the net but it seems like the error doesnt exits before.
    Thank you!

    Regards,
    tiffany

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I don't think you'll have much success searching for that message as it isn't an error. Its just the object.toString() value. As I said previously, try writing a simple test case and running the same code. You should be able to see the actual exception that is occuring.

Posting Permissions

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