25 個の要素のリストを返すクエリを Hibernate に送信しています。次に、リストを繰り返し処理して各要素を出力します。問題は、要素を繰り返し処理するのではなく、最初の要素を 25 回出力していることです。
最初のクラスのコードは次のAnalAction
とおりです。
package secondary.view;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.hibernate.Session;
import secondary.controller.AnalManager;
import secondary.controller.LocationManager;
import secondary.model.Anal_01;
import secondary.model.LocationMaster;
import com.opensymphony.xwork2.ActionSupport;
public class AnalAction extends ActionSupport implements ServletRequestAware {
private List<LocationMaster> loclist;
//private List<CustomerMaster> custList;
//private ArrayList<String> bgroup;
private ArrayList<String> Location;
public AnalAction()
{
linkcontroller=new AnalManager();
linkcontroller2=new LocationManager();
//custController=new CustomerMasterManager();
}
String target="";
public String execute()
{
try{
loclist=linkcontroller2.locList(); //calling from below class LocationManager
System.out.println("loclist.."+loclist.size());
Location=new ArrayList<String>();
Iterator<LocationMaster> iter = loclist.iterator();
while(iter.hasNext())
{
String str=iter.next().getLoc_name();
System.out.println("location name..:"+str);
Location.add(str);
target="Entry";
}
System.out.println("location..."+Location);
ここにあるLocationManager
:
package secondary.controller;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import secondary.model.LocationMaster;
import secondary.util.HibernateUtil;
public class LocationManager extends HibernateUtil {
public LocationManager(){};
@SuppressWarnings("unchecked")
public List<LocationMaster> locList()
{
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tran=null;
List<LocationMaster> loc=null;
try
{
tran=session.beginTransaction();
loc=(List<LocationMaster>) session.createQuery("from LocationMaster order by loc_code ").list();
if(loc.size()>0)
{
System.out.println("size.....j"+loc.size());
tran.commit();
}
}catch(Exception e){
e.printStackTrace();
}
return loc;
}
}