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]