When entity got detached
- when transaction is over, commited
- when application-managed persistence context is closed
- stateful bean is removed, its persistence context will be removed
- clear method call from EntityManager
- transaction rollback
- when entity is serialized
Merge process
- merge will update the managed entity if there is one.
- merge will include new entity COPY
into context
- manager will check whether there is one in Database, if there is, load it, and ignore the detached one.
- cascading operation is disabled as default
, same as merge, if merge is not set in the relationship, no merge operation as cascaded.
Merge lazy-loading entity
- if lazy-loading relationship was not triggered before detached, the relationship will be ignored.
- if its triggered while managed and set to null while detached, then managed version will have relationship cleared during merge
JPA QL
- dynamic query
- named query
set query parameter
you can use object to pass to a query, but when set date time, we use the following format
quuery.setParameter(1, startDate, TemportalType.Date)
When pass object to as parameter, the object ID
will be used in where clause
@Embeded and @Embedable
@attributeOverrides can has element @AttributeOverride to orverride attribute properties.
@compound primary key
- I dont like it personally
-
Primary key classes
- include definition: equals() hashcode(), serializable, and with no-arg constructor, annotated with @IdClass
- embeddedId, use @Embedable to define primary key class
Inheritance strategy
Single Table
- default, use @Inheritance(Strategy=InteritanceType.Single_Table) for Parent class.
- use @discriminatorColumn to differenciate sub-classes.
- Only concrete class can have @discriminatorValue specified.
- If no specified, default value will be used, the entity name
- @Enity(name="PTemp"), in this case, "PTemp" will be used as discriminator value
Join strategy
- each concret class maped to its own table, parent class has its own class
-
hard to construct sub-class, as need info from parent table
- need @DiscriminatorColumn(name="EMP_TYPE", discriminatorType=DiscriminatorType.INTEGER)
table per concret class
Hints
Named Query result will be managed in persistent context, when its synchronized with transaction, changes will be persisted. So the entity must match database, otherwise, it will overwrite database when transaction commits.
directly modify database table is discaraged as it will make managed entity inconsisten with data in table.
Refresh entity state
- refresh only applys to when entity is managed
- if eneity is not managed, then an IllegalArgumentException will be thrown
分享到:
相关推荐
学习hibernate必读,包括JPA2新特征和JPA2映射的神秘之旅两个pdf。
介绍JPA2的一本很不错的英文书籍,可以作为一本权威参考。
JPA教程JPA教程JPA教程JPA教程JPA教程
jpa jpa规范 jpa源码 jpa jpa规范 jpa源码
jpajpajpajpajpajpajpajpajpajpajpajpajpa
包括TOPLink JPA,Hibernate JPA,Open Jpa,jpa批注
JPA视频_概述 · 2. JPA视频_HelloWorld · 3. JPA视频_基本注解 · 4. JPA视频_Transient注解 · 5. JPA视频_Temporal注解 · 6. JPA视频_Table主键生成策略 · 7. JPA视频_EntityManager(1) · 8. JPA视频_...
介紹JPA2的最佳參考好書,看了之後對JPA的架構與使用有清晰了解。
Pro JPA2 书籍 代码
JPA
jpa测试用例2jpa测试用例2jpa测试用例2jpa测试用例2jpa测试用例2
jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联...
Open JPA2 employee 简单例子
实现了struts2 jpa框架的demo实例。
Spring Data JPA API。 Spring Data JPA 开发文档。 官网 Spring Data JPA API。
Pro JPA2中文版:精通Java持久化API 优秀博文读书笔记: http://www.cnblogs.com/sunshine-as-before/tag/java jpa/ 随书pdf文档和源码下载地址: http://download.csdn.net/download/vcfriend/10251462 相关学习博文...
一个简单的maven项目演示spring 整合 hibernate jpa2 实例,使用 mvn test 运行。
Spring Data JPA 简化 JPA 开发
JPA学习参考文档 JPA学习参考文档 JPA学习参考文档
这是JPA标签配置手册,从ORACLE官方得到的资料,里面对JPA所有的标签都进行详细的说明。 Index of Annotations • A o @AssociationOverride o @AssociationOverrides o @AttributeOverride o @AttributeOverrides ...