【发布时间】:2011-11-02 07:57:46
【问题描述】:
考虑以下 Hibernate 映射:
<hibernate-mapping package="org.example">
<class name="Customer" table="CUSTOMER">
<id name="customerId" column="customer_id"/>
<bag name="itineraries" table="ITINERARY" inverse="true" cascade="all">
<key column="customer_id"/>
<one-to-many class="Itinerary"/>
</bag>
<bag name="hotels" table="HOTEL" inverse="true" cascade="all">
<key column="customer_id"/>
<one-to-many class="Hotel"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping package="org.example">
<class name="Itinerary" table="ITINERARY">
<many-to-one name="customer" column="customer_id" update="false" not-null="true"/>
...other properties...
</class>
</hibernate-mapping>
<hibernate-mapping package="org.example">
<class name="Hotel" table="HOTEL">
<many-to-one name="customer" column="customer_id" update="false" not-null="true"/>
...other properties...
</class>
</hibernate-mapping>
现在假设您需要删除 CUSTOMER 表。您将如何重构映射/模型,以使 Customer Java 对象继续包含基于 customerId 的 Itinerary 和 Hotel 对象列表?上述 Hotel 和 Itinerary 对象仍然需要由 Hibernate 管理。
我能想到的最好的方法是在调用者请求列表时将 Customer 对象推迟到 DAO。是否有更简洁的方法仍然允许 Customer 对象存在于每个 Itinerary 和 Hotel 对象中?
【问题讨论】:
-
为什么要删除 CUSTOMER 表?
-
这确实是假设,但假设 CUSTOMER 表正在移动到其他无法访问的模式。
标签: java hibernate dao hibernate-mapping