报出的错误是house字段找不到,Room实体中有house属性吗

解决方案 »

  1.   

    有的,house对象属性是Room实体的一个外键。
      

  2.   

    Unknown column 'house' in 'where clause',这应该是数据库里没有house列啊
      

  3.   


    这个house对象是room实体的一个属性,对应数据是外键house_id.
      

  4.   

    直接使用实体对象的查询参数还真没用过,不过你可以
    WHERE house.id=1
      

  5.   

    试过了,这样不行org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'house.id' [select id, number,leaseTerm,rent,deposit,status,personAmount,liveStartTime,doorKey,equipment,expiryDate,,account,house FROM com.rental.domain.Room WHERE house.id=:house]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
    at com.rental.dao.impl.RoomDaoImpl.test(RoomDaoImpl.java:44)
    at junit.test.HouseServiceTest.testFind(HouseServiceTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:176)
    at junit.framework.TestCase.runBare(TestCase.java:141)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)0    [main] ERROR org.hibernate.hql.PARSER  -  Invalid path: 'house.id'
    0    [main] ERROR org.hibernate.hql.PARSER  - <AST>:0:0: unexpected end of subtree
    0    [main] ERROR org.hibernate.hql.PARSER  -  left-hand operand of a binary operator was null
      

  6.   

    有的,house对象属性是Room实体的一个外键。
    如果你的house是一个对象的话那你的hql就应该改成
    String hql=from Room where house.id=:houseId;
    lst = (List<Room>) this.getSession().createQuery(hql).setParameter("houseId", h.getId()).list();
      

  7.   

    有的,house对象属性是Room实体的一个外键。
    如果你的house是一个对象的话那你的hql就应该改成
    String hql=from Room where house.id=:houseId;
    lst = (List<Room>) this.getSession().createQuery(hql).setParameter("houseId", h.getId()).list();经验老道的大神。
      

  8.   

    有的,house对象属性是Room实体的一个外键。
    如果你的house是一个对象的话那你的hql就应该改成
    String hql=from Room where house.id=:houseId;
    lst = (List<Room>) this.getSession().createQuery(hql).setParameter("houseId", h.getId()).list();这样也不行,hql只针对对象作查询。
      

  9.   

    有的,house对象属性是Room实体的一个外键。
    如果你的house是一个对象的话那你的hql就应该改成
    String hql=from Room where house.id=:houseId;
    lst = (List<Room>) this.getSession().createQuery(hql).setParameter("houseId", h.getId()).list();这样也不行,hql只针对对象作查询。
    这有什么不行的,这本来就是查询Room对象啊,你原来把house这个对象当做查询条件自然是不行的,现在以house的外键id为查询条件就可以了
      

  10.   

    这样写可以执行查询:
    String hql="from Room where house =: house";
    lst = (List<Room>)this.geteSession().createQuery(hql).setParameter("house",h).list();把hql中的外键字段去掉后也可以执行查询:
    String hql="String hql ="select id, number,leaseTerm,rent,deposit,status,personAmount,liveStartTime,doorKey,equipment,expiryDate,,account FROM Room WHERE house =:house ";"但是hql写成下面这样为什么不行呢?在hql中加上外键字段为什么无法执行查询呢。
    String hql ="select id, number,leaseTerm,rent,deposit,status,personAmount,liveStartTime,doorKey,equipment,expiryDate,,account ,house FROM Room WHERE house =:house ";"
      

  11.   

    你这个house是一个关联对象,不是列,如果不是延迟加载hibernate在查询Room的对关联对象会自己执行关联查询了,如果是延迟加载你在getHouse的时候也会触发关联查询了,在这种设计的情况下你在用house写在hql里这就没意义了。hibernate就不支持