Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Configuring a EclipseLink JPA Application (ELUG)"

(How to Provide Authenticated Reads and Writes of Secured Data Through the Use of an Exclusive Isolated Client Session)
m
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
[[Image:Elug draft icon.png]] '''For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/ '''
 +
 +
----
 +
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
 
[[Special:Whatlinkshere/Configuring a EclipseLink JPA Application (ELUG)|Related Topics]]</div>
 
[[Special:Whatlinkshere/Configuring a EclipseLink JPA Application (ELUG)|Related Topics]]</div>
Line 49: Line 53:
 
  ((org.eclipse.persistence.internal.jpa.EntityManagerImpl)em.getDelegate()).setProperties(emProperties);
 
  ((org.eclipse.persistence.internal.jpa.EntityManagerImpl)em.getDelegate()).setProperties(emProperties);
  
For more information, see [[Using%20EclipseLink%20JPA%20Extensions%20(ELUG)#How to Use the Persistence Unit Properties for Caching|How to Use the Persistence Unit Properties for Caching]].
+
JPA 2.0 defines a new setProperty method on EntityManager that could be used instead:
 +
 
 +
em.setProperty("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
 +
em.SetProperty(oracle.jdbc.OracleConnection.PROXY_USER_NAME, "john");
  
 +
If proxy authentication properties are set when active persistence context already exists (that may happen if setProperty/setProperties method is used) then they will be ignored until a new one is created. Calling clear method on the EntityManager forces creation of the new active persistence context.
 +
 +
For more information, see [[Using%20EclipseLink%20JPA%20Extensions%20(ELUG)#How to Use the Persistence Unit Properties for Caching|How to Use the Persistence Unit Properties for Caching]].
  
 
===How to Define Proxy Properties Using EntityManagerFactory===
 
===How to Define Proxy Properties Using EntityManagerFactory===
Line 77: Line 87:
 
  cancelProperties.put("eclipselink.oracle.proxy-type", "");
 
  cancelProperties.put("eclipselink.oracle.proxy-type", "");
 
  EntityManager em3 = emf.createEntityManager(cancelProperties);
 
  EntityManager em3 = emf.createEntityManager(cancelProperties);
 +
 +
===Proxy Authentication and application servers===
 +
Oracle Proxy Authentication may have conflicts with application servers' connections that wrap the actual Oracle connection. On some application servers after the proxy session was closed the statements that used the proxy session were still kept in the statement cache - that resulted in exception on attempt to use a closed statement. To workaround set application server statement cache size to zero.
  
 
==Setting Up Packaging==
 
==Setting Up Packaging==

Latest revision as of 11:24, 18 July 2012

Elug draft icon.png For the latest EclipseLink documentation, please see http://www.eclipse.org/eclipselink/documentation/


This section contains information on how you can configure your EclipseLink persistence project.

When configuring an EclipseLink JPA application you cannot use the org.eclipselink.sessions.Project class, but you can still customize sessions and descriptors by using the customizer extensions (see Using EclipseLink JPA Extensions for Customization and Optimization).

You can set up your EclipseLink JPA application using various IDEs.

At run time, if the eclipselink.jar file is on the application classpath, you have the option to choose EclipseLink as a persistence provider for your application.


Configuring Oracle Database Proxy Authentication for a JPA Application

One of the features of the Oracle Database is proxy authentication. For more information, see Oracle Database Proxy Authentication.


How to Provide Authenticated Reads and Writes of Secured Data Through the Use of an Exclusive Isolated Client Session

If you use Oracle Virtual Private Database (VPD) (see Isolated Client Sessions and VPD), and you want to enable read and write access control for your EclipseLink JPA application, in the SessionCustomizer class set the connection policy to use exclusive connections, and define the descriptor for secured data as isolated (see Configuring Cache Isolation at the Descriptor Level). Consider the following example.

Pass properties to the createEntityManagerFactory method, as the following example demonstrates. One property should indicate that exclusive connection should be used for classes that use isolated cache. Other properties should indicate that one or more specific entities use an isolated cache,

Map properties = new HashMap();
properties.put("eclipselink.jdbc.exclusive-connection.mode", "Isolated");
properties.put("eclipselink.cache.shared.Employee", "false");
...
EntityManagerFactory emf = Persistence.createEntityManagerFactory(properties);

In the preceding example, an entity named Employee uses isolated cache and will be read and written through an exclusive connection.

To specify that all entities are to use isolated cache, set the eclipselink.cache.shared.default property to false:

properties.put("eclipselink.cache.shared.default", "false");

For more information, see How to Use the Persistence Unit Properties for Caching.

How to Provide Authenticated Writes for Database Auditing Purposes with a Client Session

If you want to enable write access control for your EclipseLink JPA application, in your SessionCustomizer class provide the EntityManager with properties similar to the ones that the following example demonstrates.

Map emProperties = new HashMap();
emProperties.put("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
emProperties.put(oracle.jdbc.OracleConnection.PROXY_USER_NAME, "john");
EntityManager em = emFactory.createEntityManager(emProperties);

In the preceding example, the EntityManager uses a proxy user "john" for writes and reads inside a transaction. Note that reads, which are performed outside of the transaction, are done through the main (non-proxied) connection.

If you created your EntityManager using injection, set the properties as follows:

((org.eclipse.persistence.internal.jpa.EntityManagerImpl)em.getDelegate()).setProperties(emProperties);

JPA 2.0 defines a new setProperty method on EntityManager that could be used instead:

em.setProperty("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
em.SetProperty(oracle.jdbc.OracleConnection.PROXY_USER_NAME, "john");

If proxy authentication properties are set when active persistence context already exists (that may happen if setProperty/setProperties method is used) then they will be ignored until a new one is created. Calling clear method on the EntityManager forces creation of the new active persistence context.

For more information, see How to Use the Persistence Unit Properties for Caching.

How to Define Proxy Properties Using EntityManagerFactory

You can also define proxy properties using the EntityManagerFactory. If you choose to do so, note that all connections will use these properties, unless they are overridden in the EntityManager. Consider the following example:

Map factoryProperties = new HashMap();
factoryProperties.put("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
factoryProperties.put(oracle.jdbc.OracleConnection.PROXY_USER_NAME, "sarah");
EntityManagerFactory emf = Persistence.createEntityManagerFactory(factoryProperties);

// em1 does not specify its own proxy properties -
// it uses proxy user "sarah" specified by the factory
EntityManager em1 = emf.createEntityManager();
 
Map emProperties = new HashMap();
emProperties.put("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
emProperties.put(oracle.jdbc.OracleConnection.PROXY_USER_NAME, "john");

// em2 uses its own proxy properties (proxy user "john"), 
// regardless of whether or not factory has proxy properties
EntityManager em2 = emf.createEntityManager(emProperties);
 
// em3 does not use any proxy connection. 
// It cancels proxy properties defined in the factory
Map cancelProperties = new HashMap();
cancelProperties.put("eclipselink.oracle.proxy-type", "");
EntityManager em3 = emf.createEntityManager(cancelProperties);

Proxy Authentication and application servers

Oracle Proxy Authentication may have conflicts with application servers' connections that wrap the actual Oracle connection. On some application servers after the proxy session was closed the statements that used the proxy session were still kept in the statement cache - that resulted in exception on attempt to use a closed statement. To workaround set application server statement cache size to zero.

Setting Up Packaging

You can package your application manually (see Packaging an EclipseLink JPA Application), or use an IDE.




Copyright Statement

Back to the top