VM-Core/src/main/java/com/validation/manager/core/server/JPAEclipseLinkSessionCustomizer.java
@Override
    public void customize(Session session) throws Exception {
        JNDIConnector connector;
        // Initialize session customizer
        DataSource dataSource;
        try {
            Context context = new InitialContext();
            if (null == context) {
                throw new VMException("Context is null");
            }
            connector = (JNDIConnector) session.getLogin().getConnector(); // possible CCE
            // Lookup this new dataSource
            dataSource = (DataSource) context.lookup(JNDI_DATASOURCE_NAME);
            connector.setDataSource(dataSource);
            // 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);

            // if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe
            JNDIConnector writeConnector
                    = (JNDIConnector) session.getLogin().getConnector();
            writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
            JNDIConnector readConnector
                    = (JNDIConnector) ((DatabaseLogin) ((ServerSession) session)
                            .getReadConnectionPool().getLogin()).getConnector();
            readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);

            // Set the new connection on the session
            session.getLogin().setConnector(connector);
        }
        catch (Exception e) {
            LOG.log(Level.SEVERE, JNDI_DATASOURCE_NAME, e);
        }
    }
@Override
    public void customize(Session session) throws Exception {
        JNDIConnector connector;
        // Initialize session customizer
        DataSource dataSource;
        try {
            Context context = new InitialContext();
            if (null == context) {
                throw new VMException("Context is null");
            }
            connector = (JNDIConnector) session.getLogin().getConnector(); // possible CCE
            // Lookup this new dataSource
            dataSource = (DataSource) context.lookup(JNDI_DATASOURCE_NAME);
            connector.setDataSource(dataSource);
            // 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);

            // if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe
            JNDIConnector writeConnector
                    = (JNDIConnector) session.getLogin().getConnector();
            writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
            JNDIConnector readConnector
                    = (JNDIConnector) ((DatabaseLogin) ((ServerSession) session)
                            .getReadConnectionPool().getLogin()).getConnector();
            readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);

            // Set the new connection on the session
            session.getLogin().setConnector(connector);
        }
        catch (Exception e) {
            LOG.log(Level.SEVERE, JNDI_DATASOURCE_NAME, e);
        }
    }
@ Override public void customize ( Session session ) throws Exception { JNDIConnector connector ; // Initialize session customizer DataSource dataSource ; try { Context context = new InitialContext ( ) ; if ( null == context ) { throw new VMException ( "Context is null" ) ; } connector = ( JNDIConnector ) session . getLogin ( ) . getConnector ( ) ; // possible CCE // Lookup this new dataSource dataSource = ( DataSource ) context . lookup ( JNDI_DATASOURCE_NAME ) ; connector . setDataSource ( dataSource ) ; // 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 ) ; // if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe JNDIConnector writeConnector = ( JNDIConnector ) session . getLogin ( ) . getConnector ( ) ; writeConnector . setLookupType ( JNDIConnector . STRING_LOOKUP ) ; JNDIConnector readConnector = ( JNDIConnector ) ( ( DatabaseLogin ) ( ( ServerSession ) session ) . getReadConnectionPool ( ) . getLogin ( ) ) . getConnector ( ) ; readConnector . setLookupType ( JNDIConnector . STRING_LOOKUP ) ; // Set the new connection on the session session . getLogin ( ) . setConnector ( connector ) ; } catch ( Exception e ) { LOG . log ( Level . SEVERE , JNDI_DATASOURCE_NAME , e ) ; } }
Get a dataSource connection and set it on the session with
lookupType=STRING_LOOKUP

@param session Session
@throws java.lang.Exception If an error occurs.
Get a dataSource connection and set it on the session with lookupType = STRING_LOOKUP