【发布时间】:2011-10-03 10:25:11
【问题描述】:
我有以下表格
------------
BAR
------------
ID
number
------------
ZOO
------------
ID
------------
FOO
------------
ID
------------
MAPPER
------------
ID
FOO
BAR
ZOO
现在我想获取特定 FOO 的所有 ZOO 所以我会这样做
select ZOO from MAPPER where zoo = someZoo
但现在我希望这些动物园根据投票数排序,这样 SQL 就可以了
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
但是现在我想在 Hibernate 中以独立于 DB 的方式进行操作,我该怎么做?
我有实体映射设置我正在使用 Spring Hibernate 模板支持
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;
}
【问题讨论】:
-
能否提供实体代码,而不是伪数据库表?
-
@James DW 添加了没有映射和东西的基本模型类