您的位置:首页 > 移动开发 > Objective-C

Hibernate笔记_object state

2016-06-16 17:31 429 查看
作为一款功能强大的ORM工具,Hibernate应该具有哪些功能?

1)对象在Hibernate中的状态:transient and persistent。

transient: never persistent, not associated with any Session

persistent: associated with a unique Session

detached: previously persistent, not associated with any Session

Transient instances may be made persistent by calling save(), persist() or saveOrUpdate(). Persistent instances may be made transient by calling delete(). Any instance returned by a get() or load() method is persistent. Detached instances may be made persistent
by calling update(), saveOrUpdate(), lock() or replicate(). The state of a transient or detached instance may also be made persistent as a new persistent instance by calling merge().

save() and persist() result in an SQL INSERT, delete() in an SQL DELETE and update() or merge() in an SQL UPDATE. Changes to persistent instances are detected at flush time and also result in an SQL UPDATE. saveOrUpdate() and replicate() result in either an
INSERT or an UPDATE.

It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.

2)从对象关联(association)的角度来设计映射

2.1)Album->Track (Fowler:Dependent Mapping)得到的映射就是OneToMany;

2.2)Album->Artist (Fowler:Foreign Key Mapping)得到的映射就是ManyToOne;

2.3)Employee->Skill(Fowler:Association Table Mapping)得到的映射就是ManyToMany;


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: