multiple levels of nesting component in JPA
I know using hibernate mapping files we can nest one component inside another. For example:
<?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=开发者_StackOverflow社区"HOLIDAY_TELEPHONE" />
</component>
<property name="address" type="string" column="HOLIDAY_ADDRESS" />
</component>
</class>
</hibernate-mapping>
As per my understanding we cannot do the same with JPA.Is the understanding correct?
As per my understanding we can do the same with JPA.Is the understanding correct?
Yes and no. JPA 1.0 supports only properties which follows the rules for the Basic annotation, meaning that it doesn't support other @Embedded. But JPA 2.0 supports it.
精彩评论