Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate gorm准则中的笛卡尔积_Hibernate_Grails_Orm_Gorm - Fatal编程技术网

Hibernate gorm准则中的笛卡尔积

Hibernate gorm准则中的笛卡尔积,hibernate,grails,orm,gorm,Hibernate,Grails,Orm,Gorm,我尝试使用CreateCriteria执行下面的sql语句,但我不知道如何使用具有不同别名的相同表。 这里是我的域名: class Analisys { Integer performanceStar Phase phase static belongsTo = [instrument: Instrument] } class Phase { String name int showOrder static hasMany = [cat

我尝试使用CreateCriteria执行下面的sql语句,但我不知道如何使用具有不同别名的相同表。 这里是我的域名:

class Analisys {

    Integer performanceStar
    Phase phase

    static belongsTo = [instrument: Instrument]

}

class Phase {

    String name
    int showOrder

    static hasMany = [category: Category]
}
class Instrument {

    Long internalId
    String name
    String description

    Date dateCreated
    Date lastUpdated

    static hasMany = [ analisys: Analisys]
}
下面是sql语句:

select *
from
    analisys as a1
inner join phase as p1 on a1.phase_id = p1.id,
 analisys as a2
inner join phase as p2 on a2.phase_id = p2.id,
 analisys as a3
left join phase as p3 on a3.phase_id = p3.id
where
a1.phase_id=100
and a2.phase_id=102
and a3.phase_id=103
and a1.instrument_id = a2.instrument_id
and a1.instrument_id = a3.instrument_id
使用CreateCriteria,我开始写这样的东西,但当然是错误的:

def results = Classification.createCriteria().list(max: 100, offset: 0) {

            instrument {
                analisys(org.hibernate.criterion.CriteriaSpecification.LEFT_JOIN) {
                    eq("phase.id", 100)
                }
            }
            instrument {
                analisys(org.hibernate.criterion.CriteriaSpecification.LEFT_JOIN) {
                    eq("phase.id", 102)
                }
            }
            instrument {

                analisys(org.hibernate.criterion.CriteriaSpecification.LEFT_JOIN) {
                    eq("phase.id", 103)
                }
            }

        }
有了HQL,我可以使用我在下面写的内容来实现它,但仍然不了解如何通过标准实现它,现在甚至不确定它是否可行:

Analisys.executeQuery(" from Analisys as a1, Analisys as a2, Analisys as a3 
where a1.phase.id=100 and a2.phase.id=102 and a3.phase.id=103 
and a1.instrument.id = a2.instrument.id and a1.instrument.id = a3.instrument.id ")
我发现了一篇有趣的文章,可以帮助那些有同样问题的人:


请包括实体映射,因为这可以帮助您更好地完成您的要求。添加域解释,希望是因为您没有提供
工具
域类,很难获得现在的整体情况。对不起,我的不好,现在已更新