Professional Documents
Culture Documents
JavaOneSessionV3 1 PDF
JavaOneSessionV3 1 PDF
Facade
Converter Class
JPA
Facade
Converter Class
JPA
Other date fields, such as day-of-year, day-of-week and week-of-year, can also be
accessed.
The ISO-8601 calendar system is the modern civil calendar system used today in most of
the world.
However, any application that makes use of historical dates, and requires them to be
accurate will find the ISO-8601 approach unsuitable.
NO
HOW TO PERSIST
LOCALDATE AND
LOCALDATETIME WITH JPA
29 © 2015 IBM Corporation
How to persist LocalDate and LocalDateTime with JPA
Converter Class
JPA
JPA 2.1 was released before Java 8 and therefore doesn’t support the new Date and Time
API.
If you want to use the new classes (in the right way), you need to define the conversion to
java.sql.Date and java.sql.Timestamp yourself.
By setting autoApply=true, the converter will be applied to all attributes of the EntityType and
no changes on the entity are required.
EAGER – immediate
Lazy load fields and relationships that are not used frequently
JPA
Facade
JPA
Facade
Facade
JPA
Facade
Facade
Advantage
If we need lots of use case specific entity graphs, it might
be better to define the entity graph within the specific Java
code and to not add an additional annotation to the entity.
Avoids entities with dozens of annotations.
Disadvantage
The dynamic entity graph requires more code and an
additional method to be reusable.
Initializing a lazy relation via calling a method on a mapped relation causes an additional
query. This should be avoided for performance reasons.
Fetch joins in JPQL statements reduce the number of queries to one but we might need a lot
of different queries.
The Criteria API also supports fetch joins and we need specific code for each combination of
relations that shall be initialized.
Named entity graphs are a good solution, if we will reuse the defined graph in our code.
Dynamic entity graphs can be the better solution, if we need to define a use case specific
graph.
QUERIES
JPQL
JPA Criteria
1. Create a Query.
– This can be done as a JPQL, native or criteria query.
– You can also define additional hints and settings for the query.
2. Find a name for your query that is unique within your persistence unit.
– If there is already a named query defined for the name, the query will be updated.
3. Use the Query and name to call the addNamedQuery(String name, Query query) method
on the EntityManagerFactory.
JPQL ENHANCEMENTS
BULK UPDATES
IN:
– for input parameters,
OUT:
– for output parameters,
INOUT:
– for parameters which are used for input and output and
REF_CURSOR:
– for cursors on a result set .
GENERATING DB SCHEMA
javax.persistence.schema-generation.database.action
javax.persistence.schema-generation.scripts.action
javax.persistence.schema-generation.create-source
javax.persistence.schema-generation.drop-source
javax.persistence.schema-generation.create-database-schemas
javax.persistence.schema-generation.scripts.create-target
javax.persistence.schema-generation.scripts.drop-target
javax.persistence.database-product-name
javax.persistence.database-major-version
javax.persistence.database-minor-version
javax.persistence.schema-generation.create-script-source
javax.persistence.schema-generation.drop-script-source
javax.persistence.schema-generation.connection
javax.persistence.sql-load-script-source
EJB LITE
TIMERSERVICE
TimerService.getAllTimers
– a newly added convenience API that returns all timers in the same bean.
– This is only for displaying the list of timers as the timer can only be cancelled by its
owner.
ansgohar
https://about.me/ansgohar
http://ansgohar.blogspot.co.uk
https://eg.linkedin.com/in/ansgohar
https://www.facebook.com/ansgohar
https://twitter.com/ansgohar