开发者

Hibernate custom HQL for this mapping

I have following tables

------------
BAR
------------
ID
number

------------
ZOO
------------
ID

------------开发者_StackOverflow社区
FOO
------------
ID

------------
MAPPER
------------
ID
FOO
BAR
ZOO

Now I want to fetch all ZOO for particular FOO So I will do

select ZOO from MAPPER where zoo = someZoo

but now I want these ZOO sorted based on vote number so SQL would be

SELECT FOOBAR.ZOO
FROM  mapper AS mapper,
BAR AS bar
WHERE mapper.FOO=SOME_VALUE AND mapper.BAR=bar.id order by bar.number desc

But now I want to do it in DB independent way in Hibernate How would I go ?

I have entities mapped setup I am using Spring Hibernate Template Support

public class Foo{
Long id;
}


public class Zoo{
Long id;
}

public class Bar{
Long id;
Long num;
}

public class Mapper{
Long id;
Long foo;
Long bar;
Long zoo;

}


Class Mapper should be:

public class Mapper {
    Long id;
    Foo foo;
    Bar bar;
    Zoo zoo;
}

Now, you can write the following HSQL query:

select mapper.zoo from Mapper mapper where mapper.foo=:foo order by mapper.bar.num desc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜