Setting a DB Session level parameter in EclipseLink for every connection?

前端 未结 1 1671
青春惊慌失措
青春惊慌失措 2021-01-14 11:46

I\'d like to set a database session variable for every session from Eclipselink. The SQL I want to execute is something like:

begin DBMS_SESSION.SET_IDENTIF         


        
相关标签:
1条回答
  • 2021-01-14 12:14

    You are executing a query on the session while it is still obtaining a connection for some other process. The connection the postConnect event is triggered for is unavailable to the session until your event finishes - that means any query on the session will be forced to obtain a different connection.

    You need to use the accessor within the SessionEvent to obtain the connection and use it to directly execute a JDBC statement. Something like

      public void postConnect(SessionEvent evt) {
        Connection connection = ((Accessor)event.getResult()).getConnection()
        Statement statement = connection.createStatement();
        statement.execute("begin DBMS_SESSION.SET_IDENTIFIER('MyApplicationName'); end;");
      }
    
    0 讨论(0)
提交回复
热议问题