title: Effective handling java.sql.SQLException: ORA-04068
body: <p>I got below Exception: </p>
  
  <pre><code>Caused by: java.sql.SQLException: ORA-04068: existing state of packages has been discarded
  ORA-04061: existing state of package body "PACKAGE_A" has been invalidated
  ORA-04065: not executed, altered or dropped package body "PACKAGE_A"
  ORA-06508: PL/SQL: could not find program unit being called: "PACKAGE_A"
  </code></pre>
  
  <p>Versions:</p>
  
  <p><code>Java 1.7.x and oracle 11.4.x</code> </p>
  
  <p><strong><em>Root cause:</em></strong> <code>PACKAGE_A</code> has state with global variable declarations. The package specification ( not body) has been recompiled &amp; java services calling <code>PACKAGE_B</code> which internally calls <code>PACKAGE_A</code>  have thrown this exception until we restart these services. </p>
  
  <p>I know that state should not be present package specification. But I am looking for feasible solution <strong><em>without code changes in JAVA</em></strong></p>
  
  <p>I have found two solution from other SE questions regarding this topic. </p>
  
  <p><strong>Option 1:</strong></p>
  
  <pre><code>Defining packages with `PRAGMA SERIALLY_REUSABLE` 
  </code></pre>
  
  <p><strong>Option 2:</strong></p>
  
  <pre><code>exec DBMS_SESSION.RESET_PACKAGE
  exec DBMS_SESSION.MODIFY_PACKAGE_STATE( DBMS_SESSION.REINITIALIZE) 
  </code></pre>
  
  <p><strong>Option 3:</strong></p>
  
  <p>Removing global variables from package.</p>
  
  <p><strong><em>If I did not go for Option 3 forever, what are the disadvantages of using Option 1 &amp; Option 2?</em></strong></p>
  
  <p><strong><em>Does these options cause performance overhead on database? 
  Does option 3 provides best solution?</em></strong></p>