Hibernate笔记_object state

来源:互联网 发布:算法博弈论中文版 pdf 编辑:程序博客网 时间:2024/06/04 20:02

作为一款功能强大的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;




0 0
原创粉丝点击