日期:2014-05-20  浏览次数:20727 次

级联查询的问题!
小弟初学hibernate 今天有一个问题 想请教各位大哥!
查询计划大厅方法里面要传进一个计划对象id根一个大厅对象id.
数据库里面存在这两个id,
但是映射到了hibernate'的类里面竟然映射成了两个对象.\
  private Long planHallId;
  private Hall hall;
  private Plan plan;
小弟现在想查询 计划大厅的id
需要计划id根大厅id作为查询条件. 可是小弟的代码怎么查都查不到!
各位可以帮帮忙,吗?


public static void main(String[] args) 
{
List list=new ArrayList();
list=queryHall("一号");
Iterator it=list.iterator();
Hall h=new Hall();
if(it.hasNext())
{
h=(Hall)it.next();
System.out.println("this is hallid");
System.out.println(h.getHallId());
}



List list0=new ArrayList();
list0=queryPlan("门","2007-11-14 10:04:00");
Iterator ite=list0.iterator();
Plan p=new Plan();
if(ite.hasNext())
{
p=(Plan)ite.next();
System.out.println("this is planid");
System.out.println(p.getPlanId());
}



List l=new ArrayList();
l=queryPlanHall(p, h);
Iterator i=l.iterator();
Planhall ph=new Planhall();
while(i.hasNext())
{
ph=(Planhall)i.next();
System.out.println("planhall id is");
System.out.println(ph.getPlanHallId());
}
}

public static List queryPlanHall(Plan plan,Hall hall)
{
List list=new ArrayList();
String HQL=null;
Session session=HibernateSessionFactory.getSession();
HQL="From Planhall as ph where ph.plan=? and ph.hall=?";
Query q=session.createQuery(HQL);
//System.out.println(plan.getPlanId());
//System.out.println(hall.getHallId());
q.setEntity(0, plan);
q.setEntity(1, hall);
//System.out.println(plan.getPlanId());
//System.out.println(hall.getHallId());
Planhall planhall=new Planhall();
Iterator iter=q.list().iterator();
while(iter.hasNext())
{
planhall=(Planhall)iter.next();
list.add(planhall);
}
return list;
}

小弟打印不出来计划大厅的id. 太奇怪了,. 希望高手指点指点.
前面两个对象的值均已取到.

------解决方案--------------------
我不会hibernate 
q.setEntity(0, plan); 
q.setEntity(1, hall);
这个是SQL语句往里放值吧, 
q.setEntity(1, plan); 
q.setEntity(2, hall);
------解决方案--------------------
你的配置文件怎么写的?

------解决方案--------------------
1楼的. 我很严肃的告诉您! 这样子我查不出数据的! 奇怪不奇怪