-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: An error terminate at getHibernateTemplate()
PostPosted: Fri Jan 05, 2007 12:23 pm 
Newbie

Joined: Fri Jan 05, 2007 12:16 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 1:44 pm 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
Can you post the error message?

wich class do your DAOHIBERNATE extend? what do you do with the dependencies provided by Spring ?

(please, use code tags)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 12:00 am 
Newbie

Joined: Fri Jan 05, 2007 12:16 pm
Posts: 2
Hi ,

There 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;

[color=red]List result = getHibernateTemplate().find("from flight where origin_city=?", city); [/color]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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 1:18 pm 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
Do you have implemented the method

Code:
setHibernateTemplate(HibernateTemplate template)


in you dao class?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.