-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: prepareCall closing connection (Weblogic/Hibernate)
PostPosted: Sat Jan 28, 2006 8:11 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I'm attempting to call a stored procedure with the connection I retrieve from the hibernate session.
I don't think the class mappings are relevant in this situation (please correct me if I'm wrong but they're not referenced from my code.)

The stored proc is called from pojo inside a weblogic. The pojo has an EJB session facade bean. The transaction type for the bean method is Requires
From what I understand this means that if the method is called outside of a UserTransaction then the container creates one for it.

Basically my code retrieves a connection from the Hibernate session
and then when it attempts to prepare the stored procedure call the connection is closed.

Hibernate version:3.1.1


Mapping documents:
This section of the hibernate.cfg.xml file determines the weblogic cxn.
<!-- Start container mode -->

<!--solves weblogic + hibernate problem CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken -->
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>

<!-- Use weblogic data source -->
<!-- Datasource connection -->
<property name="connection.datasource">com/cognotec/jdbc/primary</property>
<property name="connection.release_mode">after_statement</property>

<!-- JTA Transactions -->
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>

<!-- If enabled, the session will be automatically flushed during the before completion phase of the transaction -->
<property name="transaction.flush_before_completion">true</property>

<!--If enabled, the session will be automatically closed during the after completion phase of the transaction. -->
<property name="transaction.auto_close_session">true</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property>

<!-- Need these for the moment, if jndi on WLS is secured -->
<property name="hibernate.connection.username">weblogic</property>
<property name="hibernate.connection.password">weblogic</property>

<!-- End container mode -->
<!-- Common to standalone and in container -->

<!-- Print SQL to stdout. -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>

Code between sessionFactory.openSession() and session.close():

Code:
   _connection = session.connection();

   ResultSet rs = null;
   Long result = new Long(0);

   if (_connection != null)
       try {

      // It's in the prepareCall method that the connection is closed.[/color][i]
      _callStmt = _connection.prepareCall(TDealProcedureNames.CREATE_DEAL_STORE_PROC);
      
      // The extractData command simply fleshes out the parameters for the proc.
      // The stored proc works fine when I retrieve the connection directly from the jndi tree.
      extractData();

      // Always in a transaction
      _connection.setAutoCommit(false);

      // cursor
      _callStmt.registerOutParameter(1, Types.BIGINT);

      _callStmt.execute();

      result = _callStmt.getLong(1);

       } catch (SQLException e) {
      
      // The exception is that the Connection is closed.
      throw new PersistenceException(e.getMessage(), e);
      
       }
   return result;





Full stack trace of any exception that occurs:
java.sql.SQLException: Connection closed
at weblogic.jdbc.wrapper.JTAConnection.getXAConn(JTAConnection.java:189)
at weblogic.jdbc.wrapper.JTAConnection.checkConnection(JTAConnection.java:68)
at weblogic.jdbc.wrapper.Statement.checkStatement(Statement.java:250)
at weblogic.jdbc.wrapper.Statement.preInvocationHandler(Statement.java:101)
at weblogic.jdbc.wrapper.PreparedStatement.setNull(PreparedStatement.java:490)
at com.cognotec.domain.dal.dao.db.storedprocedures.deal.CreateDeal.extractData(CreateDeal.java:140)
at com.cognotec.domain.dal.dao.db.storedprocedures.deal.CreateDeal.createDeal(CreateDeal.java:42)
at com.cognotec.domain.dal.dao.db.impl.DealDAOImpl.createDeal(DealDAOImpl.java:44)
at com.cognotec.domain.services.booking.impl.service.DealBookerImpl.insertDeal(DealBookerImpl.java:171)
at com.cognotec.domain.services.booking.impl.service.DealBookerImpl.bookDeal(DealBookerImpl.java:113)
at com.cognotec.domain.services.booking.impl.service.DealBookerImpl.bookDeal(DealBookerImpl.java:63)
at com.cognotec.booking.impl.ejb.bean.BookingBean.bookDeal(BookingBean.java:72)
at com.cognotec.booking.impl.ejb.bean.Booking_kya53k_EOImpl.bookDeal(Booking_kya53k_EOImpl.java:133)
at com.cognotec.booking.impl.ejb.bean.Booking_kya53k_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:503)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:393)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:389)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:56)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:903)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)

Name and version of the database you are using:
Oracle 9i. (9.2.0.4.0)
Using XA drivers :- oracle.jdbc.xa.client.OracleXADataSource

The generated SQL (show_sql=true):
There's no sql as I retrieve the connection solely to call a stored procedure.

Debug level Hibernate log excerpt:
There is no hibernate log. In the first line of the extractData method that
fleshes out the args to the stored procedure I get the above :-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 9:55 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hi folks,

I think I've gotten a little further.
During the connection creation mechanism a call is made to the JTASessionContext class's getConnectionMode.

This method is hard-coded to return the AFTER_STATEMENT mode.

Later in the ConnectionManager's afterStatement method, the isAggressiveRelease method returns true because the connection mode is AFTER_STATEMENT. The Connection manager then closes the connection.

So basically I think the prepareCall method is being regarded as a statement within JTA env and as soon as the call is being prepared the connection is being closed..

Have I got this mixed up? I've set my hibernate.connection.mode to be after_transaction but as the JTASessionContext hard codes it to AFTER_STATEMENT I'm in a bit of a quandry.

Would anyone have any ideas as to how I could get around this?


Thanks,
Mark.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
yes that was a bug i introduced in 3.1.1. I just finished uploading the 3.1.2 release, which fixes that issue.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 10:40 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hey Steve,

Excellent stuff Steve, I'll give it a bash straight away.

Thanks again,
Mark.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 10:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
should mention that the current implementation of this (as with 3.1.1 btw) any functionality depending on recieving a particular type of connection here (i.e. by explicit casting) will probably break, since this method now proxies the returned connection in most cases.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 8:17 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hey Steve,

That worked like a charm. Thanks again sorted us right out.

That casting issue, are you referring to the BorrowedConnectionProxy class
I don't cast to be honest. I fill out the callable statement I retrieve from the
prepareCall method and execute it when its full.

I close both the callableStatement and connection after I'm done. Would you
know if I should do this explicitly or should I let Hibernate do it?

Thanks,
Mark.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
for the casting, i simply meant that doing something like:
Code:
OracleConnection oc = ( OracleConnection ) session.connection();
// do something specific on the oracle connection object

will break, because the proxy is not castable in that way.

it is better to call the close() methods yourself. for the borrowed connection, the proxy simply uses that to signal to the Hibernate internals that you are done with the connection, which allows it to "get back into" its normal connection release cycles.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 12:55 pm 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Great stuff Steve. We don't cast ourselves so I think we're good to go.

Might I ask you would you know of any articles/discussions online that cover
JTA and hibernate implementation? It's just I'm fairly new to both and any
info that resembles the current deployment we have here would be a huge
aid.

Thanks again for your help,
Mark.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.