我知道使用hibernate映射文件我们可以将一个组件嵌套在另一个组件中。 例如:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernaterecipes.chapter3">
<class name="Orders" table="BOOK_ORDERS">
<id name="id" type="long" column="ID">
<generator class="native" />
</id>
<component name="weekdayContact" class="Contact">
<property name="recipient" type="string" column="WEEKDAY_RECIPIENT" />
<component name="phone" class="Phone">
<property name="areaCode" type="string" column="WEEKDAY_AREACODE" />
<property name="telNo" type="string" column="WEEKDAY_TELEPHONE" />
</component>
<property name="address" type="string" column="WEEKDAY_ADDRESS" />
</component>
<component name="holidayContact" class="Contact">
<property name="recipient" type="string" column="HOLIDAY_RECIPIENT" />
<component name="phone" class="Phone">
<property name="areaCode" type="string" column="HOLIDAY_AREACODE" >
<property name="telNo" type="string" column="HOLIDAY_TELEPHONE" />
</component>
<property name="address" type="string" column="HOLIDAY_ADDRESS" />
</component>
</class>
</hibernate-mapping>
根据我的理解,我们不能对JPA做同样的事情。理解是否正确?
答案 0 :(得分:1)
根据我的理解,我们可以对JPA做同样的事情。理解是否正确?
是和否。 JPA 1.0仅支持遵循Basic annotation规则的属性,这意味着它不支持其他@Embedded。但JPA 2.0支持它。