使用:Spring,JPA2.0,Hibernate,CrudRepository
所以继承了相关的mapping-xml-parts ..
文章实体:
<entity class="net.combase.cloud.data.pojo.ArticlePojo" metadata-complete="true" >
<attributes>
///stuff following
<element-collection name="prices" target-class="net.combase.cloud.data.pojo.PricePojo" fetch="LAZY" >
<collection-table>
<join-column name="article_pojo" referenced-column-name="id" unique="false" />
</collection-table>
</element-collection>
</attributes>
</entity>
价格-嵌入式
<embeddable class="net.combase.cloud.data.pojo.PricePojo" metadata-complete="true" access="PROPERTY" >
<attributes>
<basic name="validFrom" optional="false"><temporal>TIMESTAMP</temporal></basic>
<basic name="value" optional="false" />
<many-to-one name="priceGroup" target-entity="net.combase.cloud.data.pojo.PriceGroupPojo" fetch="EAGER" optional="false"/>
<many-to-one name="organizationalUnit" target-entity="net.combase.cloud.data.pojo.OrganizationalUnitPojo" fetch="EAGER" />
</attributes>
</embeddable>
现在如果我以删除的价格保存文章..我将在日志中获得此声明:
Hibernate: delete from article_pojo_prices where article_pojo=? and price_group=? and valid_from=? and value=?
正如你所看到的...... Org-Column被忽略了...... 所以,如果我在组织上放置optional = false它会工作......事情是......我需要这个列可以为空... 有人提出任何想法吗?
度过美好的一天!