从表A,主键表B
表设计的时候A里有一个ID与B的主键关联,想通过A里的ID值查出A和B里对应的信息.
Class A
{
private B b;
//getter
//setter
}
之前我用:
B b= new B();
b.setID(1);
A a = new A();
a.setB(b);
service.findByExample(a);
去查,结果hibernate把A里所有记录全查出来了.
找不到原因,所以想改用HQL查,
请教大家下这个HQL该怎么写

解决方案 »

  1.   


    from A where A.id=B.id;
      

  2.   

    比如说查id为1的记录是不是这样写?
    from A where A.id=B.id and A.id=1
      

  3.   

    错了,是
    from A where A.id=B.id and B.id=1
      

  4.   

    from A a,B,b where a.id=b.id and b.id=1
      

  5.   

    from A a,B,b where a.id=b.id and b.id=1
    如果不行的话,先维持关系inverse然后不lazy
      

  6.   

    from B as b inner join fetch b.A where 1=1
      

  7.   

    6楼的是这个错误could not resolve property: A of: pojo.B
    5楼的也是could not resolve property: 类似的错误继续求教
      

  8.   

    Class A
    {
    private B b;
    //getter
    //setter
    }试下这个
    from A where A.b.ID = 1
      

  9.   

    通过A的id查处先关联的B的信息:
    A a=(A)session.load(A.class,id);
    a.getB();
    ……如果不行,请说明两表之间的关系。
      

  10.   

    详细请看我发的新帖:http://topic.csdn.net/u/20090521/16/90e82a83-8bce-4af8-b7da-4955dbdb7f88.html?seed=199556910