-->
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.  [ 3 posts ] 
Author Message
 Post subject: Connection, Session Closed But SQL Query gets executed?
PostPosted: Mon Jun 26, 2006 1:48 am 
Newbie

Joined: Mon Jun 26, 2006 1:41 am
Posts: 2
I am using SQL query through Hibernate.
I am surpised to see why is this below code is executing even if I've closed connection and sesion before actually executing the query.
Seems like a bug in Hibernate? Any clue?

Code:
Session session = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
session = sessionFactory.openSession();

String query = "select * from trade";

Connection connection = session.connection();

ps = connection.prepareStatement(query);

connection.close();//Inspite of this line, the lines below are working fine!!
session.close(); //Inspite of this line, the lines below are working fine!!

rs = ps.executeQuery();
int i=0;
while (rs.next()) {
i++;
}
System.out.println("rs_size="+i);

System.out.println("Done");
} catch (Exception e) {
System.out.println("Exception..."+e.getMessage());
e.printStackTrace();
}
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 2:53 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

can you show us your hibernate.cfg.xml?
If you are using the c3p0 connection pool,
the connection itself is wrapped by c3p0.
connection.close() may put the connection
back into the pool. Too the PreparedStatement
is wrapped and as soon as you work with it
the connection may be fetched from the pool.

If you do not use a connection pool,
and open the connection and session yourself via:
sessionFactory.openSession( connection );
then your code should not work.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 3:34 am 
Newbie

Joined: Mon Jun 26, 2006 1:41 am
Posts: 2
Thanks steckemetz ,

Please find attached cfg file.

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@<ip_address>:1521:<database></property>
      <property name="hibernate.connection.username"><user></property>
      <property name="hibernate.connection.password"><passwd></property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
      <!--  property name="hibernate.hbm2ddl.auto">update</property> -->
      <!-- Mapping files -->
      <mapping resource="Trade.hbm.xml"/>
</session-factory>    
</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.