+
+ /**
+ * Get a dataSource connection and set it on the session with
+ * lookupType=STRING_LOOKUP
+ *
+ *
+ */
+ public void customize(Session aSession) throws Exception {
+ JNDIConnector connector = null;
+ Context context = null;
+
+ try {
+ context = new InitialContext();
+
+ if (null != context) {
+ connector = (JNDIConnector) aSession.getLogin().getConnector(); // possible
+ // CCE
+ // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
+ // Note: if both jta and non-jta elements exist this will only
+ // change the first one - and may still result in
+ // the COMPOSITE_NAME_LOOKUP being set
+ // Make sure only jta-data-source is in persistence.xml with no
+ // non-jta-data-source property set
+
+ connector.setLookupType(JNDIConnector.STRING_LOOKUP);
+
+ // Or, if you are specifying both JTA and non-JTA in your
+ // persistence.xml then set both connectors to be safe
+ JNDIConnector writeConnector = (JNDIConnector) aSession
+ .getLogin().getConnector();
+ writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+
+ JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) aSession)
+ .getReadConnectionPool().getLogin()).getConnector();
+ readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+
+ System.out.println("JndiSessionCustomizer: configured " +
+ connector.getName());
+ } else {
+ throw new Exception("JndiSessionCustomizer: Context is null");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }