Java EE 7 is around for a few years already, and provides several very useful and long-awaited features, like entity graphs and better support for stored procedures and results mapping. For an overview, have a look at Thorben Janssen’s blog post. The query capabilities were also enhanced, with 3 additional keywords. All of them are available in both JPQL and Criteria API:
ON keyword to specify conditions for JOINs
FUNCTION to call arbitrary database function
TREAT to downcast entities to their specific type
In this post, I’ll focus on the first of them – the ON keyword in JOINs.
JPA provides essentially 2 types of locking mechanisms to help synchronize access to entities. Both mechanisms prevent a scenario, where 2 transactions overwrite data of each other without knowing it.
By entity locking, we typically want to prevent following scenario with 2 parallel transactions:
Adam’s transaction reads data X
Barbara’s transaction reads data X
Adam’s transaction modifies data X, and changes it to XA
Adam’s transaction writes data XA
Barbara’s transaction modifies data X and changes it to XB
Barbara’s transaction writes data XB
As a result, changes done by Adam are completely gone and overwritten by Barbara without her even noticing. A scenario like this is sometimes called dirty-read. Obviously, a desired result is that Adam writes XA, and Barbara is forced to review XA changes before writing XB.
<!-- turn off 2nd level caching (optional), values:
NONE, ALL, DISABLE_SELECTIVE, ENABLE_SELECTIVE, --><shared-cache-mode>NONE</shared-cache-mode><!-- desired provider (optional),
if not present, default provider will be used --><provider>org.eclipse.persistence.jpa.PersistenceProvider</provider><!-- if true, only listed classes will be treated as entities.
Not applicable for Java SE, where every entity must be listed --><exclude-unlisted-classes>false</exclude-unlisted-classes><!-- optional declaration of used datasource.
If not specified, connection properties must be specified.
Otherwise will use the referenced datasource provided by the container --><jta-data-source>jdbc/ds</jta-data-source>Code language:HTML, XML(xml)
These elements can be overridden with the following properties, if a map is passed to EntityManagerFactory:
javax.persistence.provider to define the provider class used
javax.persistence.transactionType to define the transaction type used (either JTA or RESOURCE_LOCAL)
javax.persistence.jtaDataSource to define the JTA datasource name in JNDI
javax.persistence.nonJtaDataSource to define the non JTA datasource name in JNDI
javax.persistence.lock.timeout – pessimistic lock timeout in milliseconds (Integer or String)
javax.persistence.query.timeout – query timeout in milliseconds (Integer or String)
javax.persistence.sharedCache.mode corresponds to the share-cache-mode element defined in Section 2.2.1, “Packaging”
javax.persistence.validation.mode corresponds to the validation-mode element defined in Section 2.2.1, “Packaging”
The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.