What is the best practice in order to obtain the underlying jdbc connection in Seam?

Solution Verified - Updated -

Issue

  • So we can execute CallableStatements (PL/SQL procedures) in Seam what would be the best way to get a JDBC connection handle (using the pooled connections defined in the datasource descriptor file). There are two options I can think of:

    • via JNDI-lookup

      InitialContext ctx = new InitialContext();
      dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/OracleDB");
      conn = dataSource.getConnection();
      cstmt = conn.prepareCall("{? = call DAC_VBH_1.check_something(?)}");
      ...
      
  • via the entityManager's delegate:

    Object someDelegate = entityManager.getDelegate();
    conManager = ((HibernateSessionProxy) someDelegate).getJDBCContext().getConnectionManager();
    conn = conManager.borrowConnection();
    cstmt = conn.prepareCall("{? = call DAC_VBH_1.check_something(?)}");
    ...
    

Environment

  • JBoss Enterprise Application Platform (EAP) 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.