考虑以下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的行程和酒店对象的列表?上述酒店和行程对象仍然需要由Hibernate管理。
我能想到的最好的方法是,当调用者请求列表时,Customer对象将延迟到DAOs。是否有一种更干净的方法仍然允许客户对象存在于每个行程和酒店对象中?
发布于 2011-11-02 17:04:12
一旦删除了customer表,customer对象将不再由Hibernate管理。如果您仍然希望拥有一个包含旅行者和酒店的customer对象,则需要以编程方式完成。我不确定你是不是真的在找这个。
一种可能的方法是
https://stackoverflow.com/questions/7977238
复制相似问题