`

JPA Notes 2

    博客分类:
  • JPA
阅读更多

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

  1. dynamic query
  2. 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

  1. default, use @Inheritance(Strategy=InteritanceType.Single_Table) for Parent class.
  2. use @discriminatorColumn to differenciate sub-classes.
  3. Only concrete class can have @discriminatorValue specified.
  4. If no specified, default value will be used, the entity name
  5. @Enity(name="PTemp"), in this case, "PTemp" will be used as discriminator value

Join strategy

  1. each concret class maped to its own table, parent class has its own class
  2. hard to construct sub-class, as need info from parent table
  3. 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

 

 

 

 

 

 

分享到:
评论

相关推荐

    notes_JPA_JSF:使用JSF和JPA实施来重建Notes项目

    【标题】"notes_JPA_JSF:使用JSF和JPA实施来重建Notes项目"涉及的是在Java开发环境中,利用JavaServer Faces (JSF) 和 Java Persistence API (JPA) 技术重构建一个名为Notes的项目。JSF是Java EE平台上的一个用户...

    openjpa:Apache OpenJPA

    openjpa-project / RELEASE-NOTES.html 有关文档和项目信息,请访问我们的项目站点: : 编译中 自己编译Apache OpenJPA的最佳方法是针对默认的derby数据库运行构建。 $> mvn clean install -Dsurefire.excludes....

    spring-boot-mysql-rest-api-tutorial:使用Spring Boot,Mysql,JPA和Hibernate构建Restful CRUD API

    Spring Boot,MySQL,JPA,Hibernate Rest API教程使用Spring Boot,Mysql,JPA和Hibernate为简单的记笔记应用程序构建Restful CRUD API。要求Java-1.8.x Maven-3.xx MySQL的-5.xx设定步骤1.克隆应用程序git clone ...

    Notes Java

    Java Enterprise Edition (Java EE) 是企业级应用开发的平台,包含了Servlet、JSP、EJB、JMS、JPA等技术,用于构建分布式、可扩展的应用系统。其中,Servlet和JSP是Web开发的基础,EJB则用于实现业务逻辑组件。 ...

    enseignants et étudiants (gestion des notes, annonces

    2. **JPA(Java Persistence API)**:JPA是JavaEE提供的数据持久化框架,简化了数据库操作。在教育管理系统中,可以使用JPA来管理学生和教师的信息,以及成绩和公告的数据存储。 3. **EJB(Enterprise JavaBeans)...

    cccctyl-java-basic-notes-master_java_

    【标题】"cccctyl-java-basic-notes-master_java_" 指的可能是一个关于Java基础学习的项目,其中包含了作者cccctyl对Java编程语言核心概念的深入理解和实践笔记。这个项目特别关注了权限设置和安全模块,这在任何...

    hibernate(notes)

    Hibernate是JPA(Java Persistence API)的一个实现,它提供了一套API和工具,用于将Java对象与关系数据库进行映射。这使得开发人员可以专注于业务逻辑,而无需关心底层数据库操作的细节。 二、Hibernate 安装与...

    crm:使用Spring Boot,JPA用Java编写的简单客户关系管理系统Web应用程序

    客户管理系统 Java Spring启动项目 系统要求 阿帕奇Tomcat MySQL的 Maven 目前正在进行中: 与Frontend集成 REST API端点 实体 ... " Notes " : String ... " details " : String , //like notes " r

    wicket-notes-demo:一个技术演示,使用Wicket,Spring,JPA2,JSR-303(Bean验证)在Java中实现多用户注释Webapp

    检票口演示 特拉维斯: 一个技术演示,该演示使用 , , , 在Java中实现多用户注释应用程序关于该Webapp提供了按用户备忘的功能,这意味着不同的用户可以登录和创建,阅读,更新和删除备忘。 此外,注释可以按其...

    springboot-notes-app

    4. **数据库存储(Database Storage)**:一般使用关系型数据库如MySQL或非关系型数据库如MongoDB存储笔记数据,通过JPA或MyBatis等持久层框架进行数据操作。 总结来说,"springboot-notes-app"是一个基于Spring ...

    Java+JDK+7 Learning notes.zip_java_jdk

    如果对Web开发感兴趣,可以了解Servlet、JSP、EJB、JPA等Java EE技术,它们提供了构建企业级应用的框架和组件。 总之,Java JDK 7学习笔记涵盖了Java编程的基础到高级主题,通过深入学习,不仅可以掌握Java编程的...

    notes_spring:使用Spring MVC和Spring Security实施重建Notes项目

    Spring Data JPA或MyBatis可以用来简化数据访问层的操作。你可能需要创建Repository接口,Spring Data会自动生成对应的实现,以执行CRUD操作。 总的来说,"notes_spring"项目将涵盖Web开发中的多个方面,包括但不...

    notes_javautils:java工具,框架整合

    Spring Data支持与各种数据存储的集成,如JPA(Java Persistence API)用于ORM(对象关系映射),而Spring MVC则是Web应用开发的强有力选择。 此外,"notes_javautils"可能还包括了对Java集合框架的深入理解,如...

    Assessment:Linux夏令营-Spring Notes-评估

    2. **AOP**:Spring的AOP允许开发者定义“切面”,即关注点的分离,如日志记录、事务管理等。通过代理模式,AOP可以在不修改原始代码的情况下插入这些关注点。 3. **MVC架构**:Spring MVC是用于构建Web应用的模块...

    android-notes-app-backend:使用Java for Android及其Spring Boot REST API制作的Notes应用程序

    在本项目中,“android-notes-app-backend”是一个使用Java语言开发的Android笔记应用的后端部分,结合了Spring Boot框架来构建RESTful API服务。这个应用的主要目标是为Android客户端提供数据存储和检索功能,使...

    spring-notes:用于演示Spring Boot的简单CRUD API

    2. **Repository 接口**:Spring Data 自动为实体类生成对应的 repository 接口。你只需要定义一个接口,继承 `JpaRepository` 或 `CrudRepository`,并指定实体类和主键类型。这样,你就可以直接使用接口的方法进行...

    java8stream源码-StudyNotes:学习笔记

    StudyNotes [TOC] Java Java编程思想 Spring in action Java8实战 自己的Java学习笔记 为什么说HashMap是不安全的(即将开坑...) 什么是 APT(annotation processing tool) MARK 翻译 前端 Vue.js实战 HTTP 转载 JPA

    javaNotes

    10. **Java EE**:如果深入到企业级开发,Java EE(现为Jakarta EE)是必须了解的,包括Servlet、JSP、JDBC、JPA、EJB等技术,它们构建了现代Web应用程序的基础。 11. **框架**:如Spring、MyBatis、Hibernate等...

    java-notes

    11. **Java EE**:如果"java-notes"涉及到Java企业版,那么还可能包含Servlet、JSP、EJB、JMS、JPA等Web开发和企业服务的相关知识。 12. **最新的Java版本特性**:随着Java的不断更新,如Java 8的Lambda表达式、...

    Interview_Notes:互联网大厂技术面笔记,学习路线,进行开发

    2. **面向对象编程**:深入理解OOP(面向对象编程)原则,如单一职责原则、开闭原则、里氏替换原则、依赖倒置原则和接口隔离原则,以及如何设计具有良好封装性和可扩展性的类和接口。 3. **集合框架**:掌握...

Global site tag (gtag.js) - Google Analytics