JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-001区分entities and value types...

一、介绍

1.这种引用方式不对,但删除时不能级联

 

要这种引用方式

2.The Bid class could be a problem. In object-oriented modeling, this is marked as a composition (the association between Item and Bid with the diamond). Thus, an Item is the owner of its Bid instances and holds a collection of references. At first, this seems reasonable, because bids in an auction system are useless when the item they

were made for is gone.But what if a future extension of the domain model requires a User#bids collection, containing all bids made by a particular User ? Right now, the association between Bid and User is unidirectional; a Bid has a bidder reference. What if this was bidirectional?
In that case, you have to deal with possible shared references to Bid instances, so the Bid class needs to be an entity. It has a dependent life cycle, but it must have its own identity to support (future) shared references.

3.编写实体类和值对象时,注意以下3点:

(1)Shared references—Avoid shared references to value type instances when you write your POJO classes.

 

(2)Life cycle dependencies—If a User is deleted, its Address dependency has to be deleted as well.

 

(3)Identity—Entity classes need an identifier property in almost all cases. Value type classes (and of course JDK classes such as String and Integer ) don’t have an identifier property, because instances are identified through the owning entity.

转载于:https://www.cnblogs.com/shamgod/p/5351547.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值