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.

时间: 2024-10-20 21:12:57

JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-001区分entities and value types的相关文章

JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-003映射实体时的可选操作(<delimited-identifiers/>、PhysicalNamingStrategy、PhysicalNamingStrategyStandardImpl、、、)

一.自定义映射的表名 1. 1 @Entity 2 @Table(name = "USERS") 3 public class User implements Serializable { 4 // ... 5 } 2.用定界符 1 //@Table(name = "`USER`")的标准 2 @Table(name = "`USER`") 3 4 //JPA的标准 5 @Table(name = "\"USER\"

JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-002identity详解

一.简介 1.You now have three methods for distinguishing references: ? Objects are identical if they occupy the same memory location in the JVM . This can be checked with the a == b operator. This concept is known as object identity.? Objects are equal i

JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-004Table per class hierarchy(@Inheritance..SINGLE_TABLE)、@DiscriminatorColumn、@DiscriminatorValue、@DiscriminatorFormula)

一.结构 You can map an entire class hierarchy to a single table. This table includes columns for all properties of all classes in the hierarchy. The value of an extra type discriminator column or formula identifies the concrete subclass represented by a

JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-004嵌套组件的注解AttributeOverrides

一.数据库 二.代码 1. 1 package org.jpwh.model.advanced; 2 3 import javax.persistence.AttributeOverride; 4 import javax.persistence.AttributeOverrides; 5 import javax.persistence.Column; 6 import javax.persistence.Embeddable; 7 import javax.validation.constr

JavaPersistenceWithHibernate第二版笔记-第七章-004Mapping a map(@MapKeyEnumerated 、 @MapKeyTemporal、@MapKeyColumn)

一.结构 二.代码 1. 1 package org.jpwh.model.collections.mapofstrings; 2 3 import org.jpwh.model.Constants; 4 5 import javax.persistence.CollectionTable; 6 import javax.persistence.Column; 7 import javax.persistence.ElementCollection; 8 import javax.persist

JavaPersistenceWithHibernate第二版笔记-第七章-003Mapping an identifier bag(@OrderColumn、@ElementCollection、@CollectionTable、、)

一.结构 二.代码 1. 1 package org.jpwh.model.collections.listofstrings; 2 3 import org.jpwh.model.Constants; 4 5 import javax.persistence.CollectionTable; 6 import javax.persistence.Column; 7 import javax.persistence.ElementCollection; 8 import javax.persis

JavaPersistenceWithHibernate第二版笔记-第七章-001Mapping a set(@ElementCollection、@CollectionTable、@JoinColumn、)

一.结构 二.代码 1. 1 package org.jpwh.model.collections.setofstrings; 2 3 import org.jpwh.model.Constants; 4 5 import javax.persistence.CollectionTable; 6 import javax.persistence.Column; 7 import javax.persistence.ElementCollection; 8 import javax.persist

Python核心编程(第二版) 第四章习题答案

4-1.Python对象.与所有Python对象有关的三个属性是什么?请简单的描述一下.答:与所有Python对象有关的三个属性是身份.类型.值.身份:每一个对象都有一个唯一的身份标识自己,任何对象的身份可以使用内建函数id()来得到.这个值可以被认为是该对象的内存地址.类型:对象的类型决定了该对象可以保存什么类型的值,可以进行什么样的操作,以及遵循什么规则.可以用内建函数type()来查看Python的类型.值:对象表示的数据项.4-2.类型.不可更改(immutable)指的是什么?Pyth

JavaPersistenceWithHibernate第二版笔记Getting started with ORM-001用JPA和Hibernate实现HellowWorld(JTA、Bitronix)

一.结构 二.model层 1. 1 package org.jpwh.model.helloworld; 2 3 import javax.persistence.Entity; 4 import javax.persistence.GeneratedValue; 5 import javax.persistence.GenerationType; 6 import javax.persistence.Id; 7 8 /* 9 Every persistent entity class mus