0 Replies Latest reply on May 12, 2009 4:01 PM by Jonathan Tougas

    proper way to cast to OracleConnection

    Jonathan Tougas Newbie

      I'm using seam 2.1.1.GA + jboss 5.0.0.GA + hibernate, and I'm to find the proper way to get to the underlying OracleConnection from an entityManager. (I need to call setSessionTimeZone on the OracleConnection)

      For the moment, I've got a hibernate interceptor that calls setSessionTimezone on this seam component from onPrepareStatement.

      @In
       private EntityManager entityManager;
      
       @Logger
       private Log log;
      
       private Session getHibernateSession() {
       return (Session) entityManager.getDelegate();
       }
      
       public void setSessionTimezone(OracleConnection connection) throws SQLException {
       String currentTZ = connection.getSessionTimeZone();
       String vmTZ = TimeZone.getDefault().getID();
       if( currentTZ == null || currentTZ != vmTZ) {
       connection.setSessionTimeZone( vmTZ );
       }
       }
      
       public void setSessionTimezone() {
       Connection c = getHibernateSession().connection();
       try {
       setSessionTimezone((OracleConnection) c.getMetaData().getConnection());
       c.close();
       c = null;
       } catch (Exception e) {
       if (c != null) {
       try {
       c.close();
       } catch (Exception e2) {}
       }
       throw new RuntimeException(e);
       }
       }


      Now this works more or less; I'm getting this in the logs since this has been added:

      15:44:50,242 INFO [org.jboss.resource.connectionmanager.TxConnectionManager] throwable from unregister connection
      java.lang.IllegalStateException: Trying to return an unknown connection2! org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@2189b8
       at org.jboss.resource.connectionmanager.CachedConnectionManager.unregisterConnection(CachedConnectionManager.java:330)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:720)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.closeHandle(BaseWrapperManagedConnection.java:362)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.close(WrappedConnection.java:155)
       at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:97)
       at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
       at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
       at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:304)
       at org.hibernate.jdbc.ConnectionManager.flushEnding(ConnectionManager.java:503)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
       at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
       at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)
       at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
       at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:614)
       at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
       at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:343)
       at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:243)
       at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
       at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       [snip...]


      What does this message mean exactly? I figure I'm doing something wrong. Can someone point out what's wrong here or an alternative way of doing this?

      Cheers,
      John