HQL加入路径预计加入

时间:2014-09-03 11:45:02

标签: java hibernate left-join hql

我有一个Java类 Application.java

public class Application implements Serializable {
    private Long key;
    private String appName;
    private Long locationKey;
    private Long ownerKey;
    private Long unitKey;
    private Boolean active;

    //getters and setters
}

locationKey对应于位置表,ownerKey表示Person表,unitKey表示Unit表。我没有提到表之间的任何关系。

我想检索一个应用程序列表,其中包含相应的位置,所有者和单位名称。

我创建了一个新的Java类。的 AplicationDetail.java

public class ApplicationDetails implements Serializable {
    private Long key;
    private String appName;
    private String location;
    private String ownerName;
    private String unitName;

    public ApplicationDetails(){
    }

    public ApplicationDetails(Long key, String appName, String location, String ownerName, String unitName){
        super();
        this.key=key;
        this.appName=appName;
        this.location=location;
        this.ownerName=ownerName;
        this.unitName=unitName;
    }

    //getters and setters
}

在dao中,我写了以下查询。

"select new com.myapp.domain.ApplicationDetail(application.key, application.appName, location.name as location, person.firstName || person.lastName as ownerName, unit.name as unitName)
from Application application, Location location, Person person, Unit unit 
where application.isCurrent = ? and application.locationKey = location.locationKey
and application.ownerKey = person.personKey and application.unitKey = unit.unitKey";

通过上面的查询,我得到了具有适当值的应用程序列表。但问题是它没有返回所有应用程序行。

有时,tableKey或ownerKey或unitKey在表中可以为null。或者,包含行的键可能不存在于相应的关联表中。

在任何情况下,我希望所有应用程序返回满足条件active为true;

所以我写了 LEFT OUTER JOIN QUERY。

"select new com.myapp.domain.ApplicationDetail(application.key, application.appName, location.name as location, person.firstName || person.lastName as ownerName, unit.name as unitName)
from Application application
LEFT OUTER JOIN Location location WITH application.locationKey = location.locationKey
LEFT OUTER JOIN Person person WITH application.ownerKey = person.personKey
LEFT OUTER JOIN Unit unit WITH application.unitKey = unit.unitKey
where application.isCurrent = ?";

但是当我跑步时,我得到了异常

03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(54) |  Path expected for join!
03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(50) |  Path expected for join!
 Path expected for join!

。 。 。 。

03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(54) |  Invalid path: 'dimLocation.locationName'
03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(50) |  Invalid path: 'dimLocation.locationName'
 Invalid path: 'location.name

同样适用于其他领域。它也显示没有构造函数。

03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(54) |  Unable to locate appropriate constructor on class [com.myapp.domain.ApplicationDetail]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.myapp.domain.ApplicationDetail]
03 Sep 2014 17:05:02 ERROR [tomcat-http--32] ErrorCounter.reportError(50) |  Unable to locate appropriate constructor on class [com.myapp.domain.ApplicationDetail]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.myapp.domain.ApplicationDetail]
 Unable to locate appropriate constructor on class [com.myapp.domain.ApplicationDetail]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.myapp.domain.ApplicationDetail]

但是我的 ApplicationDetails.java 中的构造函数带有参数。

'

0 个答案:

没有答案