【发布时间】:2012-01-30 07:19:08
【问题描述】:
在数据库上,我有这两张表:
- Destination:
- idDestination
- name
- Airport:
- idAirport
- idDestination // FK into Destination city
- name
地点:
- 1 个目的地(阅读:城市)有许多机场
- 1 个机场属于 1 个城市
- 因此:Destination-Airports 之间的 1-Many 关系
我的 Java 类如下所示:
class Destination{
private Integer idDestination;
private String name;
// getter and setters
}
class Airport{
private Integer idAirport;
private Destination city;
private String name;
}
// Separate class for airports in city, since city is being used in a lot of other places
// and I'd like to keep Destination class clean
class CityAirports{
private Destination City;
private Set<Airport> airports;
}
休眠映射:Airport.hbm.xml
<hibernate-mapping>
<class name="org.wah.dao.Airport" table="AIRPORT">
<id name="idAirport" type="java.lang.Integer">
<column name="IDAIRPORT" />
<generator class="identity" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<many-to-one name="city" class="org.wah.dao.Destination">
<column name="IDCITY" />
</many-to-one>
</class>
</hibernate-mapping>
我需要为 CityAirports 定义另一个映射到 - 检索城市内的所有机场。 - 为城市添加一个新机场。
我不确定休眠映射会是什么样子?有人可以指导我怎么做吗?
【问题讨论】:
标签: java hibernate jakarta-ee hibernate-mapping