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 :-