SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Albert
junyuo@gmail.com
OCEJPA Study Notes
1
Entity Relationship
2
Entity Relationship
Annotation Description
@CollectionTable 要與@ElementCollection一起使用。當Map value type是basic type
or embeddable class,適用於@CollectionTable。
@ElementCollection 若是Map<entity, basic type>,就一定要用@ElementCollection
(Map value是basic type或embedded class), 如Map<Customer,
String>
@OneToMany、
@ManyToMany
若Map value是entity,則要用@OneToMany、@ManyToMany, 如
Map<String, Customer>
@MapKeyJoinColumn 用於map key是用entity的狀況, 如Map<Customer, String>
@MapKeyColumn map key只能接受basic typeManyToMany, 如Map<String,
Customer>
@OrderColumn 只能用於@OneToMany與@ManyToMany,而且要與
@ElementCollection一起用(與relationship中的owing side無關)
@MapKey與@MapKeyClass只能擇一使用
3
@JoinTable Apply to…
4
 many-to-many and unidirectional one-to-many associations
(assign on owning side)
 bidirectional many-to-one/one-to-many associations
 unidirectional many-to-one relationships
 one-to-one associations (both bidirectional and unidirectional)
A B
A B
A B
A B
A B
A B
A Bm n
1 n
n 1
1 n
n 1
1 1
1 1
Rule for Maps
Rules for Maps Description
Use the @MapKeyClass and targetEntity
/targetClass elements of the relationship
and element collection mappings
specify the classes when an untyped Map is used
Use @MapKey with one-to-many or
many-to-many relationship Map
keyed on an attribute of the target entity
Use @MapKeyJoinColumn override the join column of the entity key.
Use @Column override the column storing the values of an element
collection of basic types
Use @MapKeyColumn override the column storing the keys when keyed by
a basic type
Use @MapKeyTemporal and
@MapKeyEnumerated
if you need to further qualify a basic key that is a
temporal or enumerated type
Use @AttributeOverride with a “key.” or
“value.” prefix
override the column of an embeddable attribute type
that is a Map key or a value, respectively
5
6
Lock
7
Valid LockType
TYPE OPTIMISTIC Description
READ OPTIMISTIC Prevents dirty read and non-repeatable
read
WRITE OPTIMISTIC_FORECE_INCREMENT Prevents dirty read and non-repeatable
read as well as increments the version of
the object
TYPE PESSIMISTIC Description
READ PESSIMISTIC_READ Prevents dirty read and non-repeatable
read
WRITE PESSIMISTIC_WRITE Prevents dirty read and non-repeatable
read as well as increments the version of
the object
8
Lock
9
Request
for
Pessimistic
lock
Tx-level
rollback
Statement-
level
rollback
PessimisticLockException LockTimeoutException
Exception
10
Rollback issue
If a system exception occurs within a transaction, the EJB container rolls back the transaction.
However, if an application exception is thrown within a transaction, the container does not
roll back the transaction.
ExceptionApplication
Exception
System Exception
• Checked
Exception
• Unchecked
Exception
EJB container doesn't roll back
the tx unless it is asked
to do so explicitly
EJB container rolls back the
Tx (if within tx)
11
EJBException or RemoteException
 A system exception in bean’s method translates to an
EJBException for a local client and a RemoteException
for a remote client
System
Exception
EJB
Exception
Remote
Exception
To local client To remote client
12
JPA Exceptions
Exception Name ThrowWhen Rollback
NoResultException Query.getSingleResult or
TypedQuery.getSingleResult is invoked and
there is no result to return.
No
NonUniqueResultException Query.getSingleResult or
TypedQuery.getSingleResult is invoked and
there is more than one result from the query.
No
QueryTimeoutException A query times out and only the statement is rolled
back
No
LockTimeoutException A pessimistic locking conflict occurs that does not
result in transaction rollback.
Typically this occurs because the database uses
statement-level rollback when a pessimistic lock
cannot be granted (and there is no deadlock).
No
13
JPA Exceptions – cont.
Exception Name ThrowWhen Rollback
TransactionRequiredException Transaction is required but is not active Yes
OptimisticLockException An optimistic locking conflict occurs.
This exception may be thrown as part of anAPI call,
at flush, or at commit time.
Yes
PessimisticLockException A pessimistic locking conflict occurs. Yes
RollbackException EntityTransaction.commit is failed Yes
EntityExistsException The persist operation is invoked and the entity
already exists.
Yes
EntityNotFoundException An entity reference obtained by getReference is
accessed but the entity does not exist.
It is thrown by the refresh operation when the
entity no longer exists in the database.
It is also thrown by the lock operation when
pessimistic locking is used and the entity no longer
exists in the database.
Yes
14
Exception
15
Persistence
Exception
EntityExists
Exception
EntityNotFound
Exception
NonUniqueResult
Exception
NoResult
Exception
OptimisticLock
Exception
Rollback
Exception
TransactionRequired
Exception
Exception
16
EJBException
EJBTransactionRolledback
Exception
TransactionRequiredLocal
Exception
TransactionRolledbackLocal
Exception
EJBTransactionRequired
Exception
EJBException is kind of system exception.When a bean method encounters system exception,
the bean instance will be discarded, and the transaction will be marked for roll back.
Entity Manager
17
Propagation of Persistence Context
18
Only applied for local
environment, not for
remote
Only for container
managed entity managers
Propagation support for all
kinds of bean
Eliminate the need to pass the
reference of EntityManager in
method call
EntityManager’s clear() method
19
Can be called on any type of
entity manager
Caused all managed entities to
become detached
When is tx scoped persistence context
created
Container Managed Entity
Manager
Bean Managed Entity
Manager
20
 When the entity is invoked
in the scope of an active
JTA tx
 As soon as an
EntityManager is created

Contenu connexe

Similaire à OCEJPA Study Notes

Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
JavaOne 2007 - TS4721
JavaOne 2007 - TS4721 JavaOne 2007 - TS4721
JavaOne 2007 - TS4721 Edgar Silva
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingTal Melamed
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answersbestonlinetrainers
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
Android - Preventing common memory leaks
Android - Preventing common memory leaksAndroid - Preventing common memory leaks
Android - Preventing common memory leaksAli Muzaffar
 
How to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupHow to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupBala Subra
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Umar Ali
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio) rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere Miklos Csere
 

Similaire à OCEJPA Study Notes (20)

Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
JavaOne 2007 - TS4721
JavaOne 2007 - TS4721 JavaOne 2007 - TS4721
JavaOne 2007 - TS4721
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answers
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Spring overview
Spring overviewSpring overview
Spring overview
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Android - Preventing common memory leaks
Android - Preventing common memory leaksAndroid - Preventing common memory leaks
Android - Preventing common memory leaks
 
How to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check TuneupHow to ace your .NET technical interview :: .Net Technical Check Tuneup
How to ace your .NET technical interview :: .Net Technical Check Tuneup
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
PHP 7
PHP 7PHP 7
PHP 7
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
 

Plus de Guo Albert

AWS IAM (Identity and Access Management) Policy Simulator
AWS IAM (Identity and Access Management) Policy SimulatorAWS IAM (Identity and Access Management) Policy Simulator
AWS IAM (Identity and Access Management) Policy SimulatorGuo Albert
 
TOEIC 準備心得
TOEIC 準備心得TOEIC 準備心得
TOEIC 準備心得Guo Albert
 
DBM專案環境建置
DBM專案環境建置DBM專案環境建置
DBM專案環境建置Guo Albert
 
JPA Optimistic Locking With @Version
JPA Optimistic Locking With @VersionJPA Optimistic Locking With @Version
JPA Optimistic Locking With @VersionGuo Albert
 
How to avoid check style errors
How to avoid check style errorsHow to avoid check style errors
How to avoid check style errorsGuo Albert
 
NIG系統報表開發指南
NIG系統報表開發指南NIG系統報表開發指南
NIG系統報表開發指南Guo Albert
 
Ease Your Effort of Putting Data into History Table
Ease Your Effort of Putting Data into History TableEase Your Effort of Putting Data into History Table
Ease Your Effort of Putting Data into History TableGuo Albert
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引Guo Albert
 
NIG系統開發文件閱讀步驟
NIG系統開發文件閱讀步驟NIG系統開發文件閱讀步驟
NIG系統開發文件閱讀步驟Guo Albert
 
Form Bean Creation Process for NIG System
Form Bean Creation Process for NIG SystemForm Bean Creation Process for NIG System
Form Bean Creation Process for NIG SystemGuo Albert
 
A Short Intorduction to JasperReports
A Short Intorduction to JasperReportsA Short Intorduction to JasperReports
A Short Intorduction to JasperReportsGuo Albert
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationGuo Albert
 
Utilize Commons BeansUtils to do copy object
Utilize Commons BeansUtils to do copy objectUtilize Commons BeansUtils to do copy object
Utilize Commons BeansUtils to do copy objectGuo Albert
 
Apply my eclipse to do entity class generation
Apply my eclipse to do entity class generationApply my eclipse to do entity class generation
Apply my eclipse to do entity class generationGuo Albert
 
Nig project setup quickly tutorial
Nig project setup quickly tutorialNig project setup quickly tutorial
Nig project setup quickly tutorialGuo Albert
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplateGuo Albert
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkGuo Albert
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvcGuo Albert
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03Guo Albert
 

Plus de Guo Albert (20)

AWS IAM (Identity and Access Management) Policy Simulator
AWS IAM (Identity and Access Management) Policy SimulatorAWS IAM (Identity and Access Management) Policy Simulator
AWS IAM (Identity and Access Management) Policy Simulator
 
TOEIC 準備心得
TOEIC 準備心得TOEIC 準備心得
TOEIC 準備心得
 
DBM專案環境建置
DBM專案環境建置DBM專案環境建置
DBM專案環境建置
 
JPA Optimistic Locking With @Version
JPA Optimistic Locking With @VersionJPA Optimistic Locking With @Version
JPA Optimistic Locking With @Version
 
How to avoid check style errors
How to avoid check style errorsHow to avoid check style errors
How to avoid check style errors
 
NIG系統報表開發指南
NIG系統報表開發指南NIG系統報表開發指南
NIG系統報表開發指南
 
Ease Your Effort of Putting Data into History Table
Ease Your Effort of Putting Data into History TableEase Your Effort of Putting Data into History Table
Ease Your Effort of Putting Data into History Table
 
NIG 系統開發指引
NIG 系統開發指引NIG 系統開發指引
NIG 系統開發指引
 
NIG系統開發文件閱讀步驟
NIG系統開發文件閱讀步驟NIG系統開發文件閱讀步驟
NIG系統開發文件閱讀步驟
 
Form Bean Creation Process for NIG System
Form Bean Creation Process for NIG SystemForm Bean Creation Process for NIG System
Form Bean Creation Process for NIG System
 
A Short Intorduction to JasperReports
A Short Intorduction to JasperReportsA Short Intorduction to JasperReports
A Short Intorduction to JasperReports
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report Implementation
 
Utilize Commons BeansUtils to do copy object
Utilize Commons BeansUtils to do copy objectUtilize Commons BeansUtils to do copy object
Utilize Commons BeansUtils to do copy object
 
Apply my eclipse to do entity class generation
Apply my eclipse to do entity class generationApply my eclipse to do entity class generation
Apply my eclipse to do entity class generation
 
Nig project setup quickly tutorial
Nig project setup quickly tutorialNig project setup quickly tutorial
Nig project setup quickly tutorial
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplate
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC Framework
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 

Dernier

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

OCEJPA Study Notes

  • 3. Entity Relationship Annotation Description @CollectionTable 要與@ElementCollection一起使用。當Map value type是basic type or embeddable class,適用於@CollectionTable。 @ElementCollection 若是Map<entity, basic type>,就一定要用@ElementCollection (Map value是basic type或embedded class), 如Map<Customer, String> @OneToMany、 @ManyToMany 若Map value是entity,則要用@OneToMany、@ManyToMany, 如 Map<String, Customer> @MapKeyJoinColumn 用於map key是用entity的狀況, 如Map<Customer, String> @MapKeyColumn map key只能接受basic typeManyToMany, 如Map<String, Customer> @OrderColumn 只能用於@OneToMany與@ManyToMany,而且要與 @ElementCollection一起用(與relationship中的owing side無關) @MapKey與@MapKeyClass只能擇一使用 3
  • 4. @JoinTable Apply to… 4  many-to-many and unidirectional one-to-many associations (assign on owning side)  bidirectional many-to-one/one-to-many associations  unidirectional many-to-one relationships  one-to-one associations (both bidirectional and unidirectional) A B A B A B A B A B A B A Bm n 1 n n 1 1 n n 1 1 1 1 1
  • 5. Rule for Maps Rules for Maps Description Use the @MapKeyClass and targetEntity /targetClass elements of the relationship and element collection mappings specify the classes when an untyped Map is used Use @MapKey with one-to-many or many-to-many relationship Map keyed on an attribute of the target entity Use @MapKeyJoinColumn override the join column of the entity key. Use @Column override the column storing the values of an element collection of basic types Use @MapKeyColumn override the column storing the keys when keyed by a basic type Use @MapKeyTemporal and @MapKeyEnumerated if you need to further qualify a basic key that is a temporal or enumerated type Use @AttributeOverride with a “key.” or “value.” prefix override the column of an embeddable attribute type that is a Map key or a value, respectively 5
  • 6. 6
  • 8. Valid LockType TYPE OPTIMISTIC Description READ OPTIMISTIC Prevents dirty read and non-repeatable read WRITE OPTIMISTIC_FORECE_INCREMENT Prevents dirty read and non-repeatable read as well as increments the version of the object TYPE PESSIMISTIC Description READ PESSIMISTIC_READ Prevents dirty read and non-repeatable read WRITE PESSIMISTIC_WRITE Prevents dirty read and non-repeatable read as well as increments the version of the object 8
  • 11. Rollback issue If a system exception occurs within a transaction, the EJB container rolls back the transaction. However, if an application exception is thrown within a transaction, the container does not roll back the transaction. ExceptionApplication Exception System Exception • Checked Exception • Unchecked Exception EJB container doesn't roll back the tx unless it is asked to do so explicitly EJB container rolls back the Tx (if within tx) 11
  • 12. EJBException or RemoteException  A system exception in bean’s method translates to an EJBException for a local client and a RemoteException for a remote client System Exception EJB Exception Remote Exception To local client To remote client 12
  • 13. JPA Exceptions Exception Name ThrowWhen Rollback NoResultException Query.getSingleResult or TypedQuery.getSingleResult is invoked and there is no result to return. No NonUniqueResultException Query.getSingleResult or TypedQuery.getSingleResult is invoked and there is more than one result from the query. No QueryTimeoutException A query times out and only the statement is rolled back No LockTimeoutException A pessimistic locking conflict occurs that does not result in transaction rollback. Typically this occurs because the database uses statement-level rollback when a pessimistic lock cannot be granted (and there is no deadlock). No 13
  • 14. JPA Exceptions – cont. Exception Name ThrowWhen Rollback TransactionRequiredException Transaction is required but is not active Yes OptimisticLockException An optimistic locking conflict occurs. This exception may be thrown as part of anAPI call, at flush, or at commit time. Yes PessimisticLockException A pessimistic locking conflict occurs. Yes RollbackException EntityTransaction.commit is failed Yes EntityExistsException The persist operation is invoked and the entity already exists. Yes EntityNotFoundException An entity reference obtained by getReference is accessed but the entity does not exist. It is thrown by the refresh operation when the entity no longer exists in the database. It is also thrown by the lock operation when pessimistic locking is used and the entity no longer exists in the database. Yes 14
  • 16. Exception 16 EJBException EJBTransactionRolledback Exception TransactionRequiredLocal Exception TransactionRolledbackLocal Exception EJBTransactionRequired Exception EJBException is kind of system exception.When a bean method encounters system exception, the bean instance will be discarded, and the transaction will be marked for roll back.
  • 18. Propagation of Persistence Context 18 Only applied for local environment, not for remote Only for container managed entity managers Propagation support for all kinds of bean Eliminate the need to pass the reference of EntityManager in method call
  • 19. EntityManager’s clear() method 19 Can be called on any type of entity manager Caused all managed entities to become detached
  • 20. When is tx scoped persistence context created Container Managed Entity Manager Bean Managed Entity Manager 20  When the entity is invoked in the scope of an active JTA tx  As soon as an EntityManager is created