• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unable to get hibernate session

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am facing a problem while working with the following code. sf.openSession() making the control go to finally block without giving any exception there. Please help me with this.

code :
Session session = null;
Transaction tx = null;
try{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
session = sf.openSession();
tx = session.beginTransaction();
System.out.println("inserting record");
session.save(dto);
tx.commit();
System.out.println("record saved");
}catch(Exception e){
e.printStackTrace();
throw new Exception(e.fillInStackTrace());
}finally{
session.close();

}


Additional Info : I am using hibernate 3 jar file. And the same code working fine when i run it in a stand alone application. But not working with web application.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naveen,
Welcome to Coderanch..

How you know control is going to finally block? My guess is, it could have thrown an exception in that line..
perhaps you could post the relevant server logs here..
 
Nav een
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prasad,

I know that because i tried running this code with sysouts and debugged the code as well. But, couldn't understand why it is going to finally from openSession() method.


The below is the log..

May 22, 2011 7:08:20 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
May 22, 2011 7:08:20 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 22, 2011 7:08:20 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
May 22, 2011 7:08:20 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 22, 2011 7:08:20 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
May 22, 2011 7:08:20 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
May 22, 2011 7:08:20 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : tracker.hbm.xml
May 22, 2011 7:08:21 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.nav.tracker.hdto.JournalDTO -> JOURNAL_MAS
May 22, 2011 7:08:21 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
May 22, 2011 7:08:21 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 22, 2011 7:08:21 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
May 22, 2011 7:08:21 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
May 22, 2011 7:08:21 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/trackerdb
May 22, 2011 7:08:21 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.5.11
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.16 ( Revision: ${bzr.revision-id} )
May 22, 2011 7:08:21 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
May 22, 2011 7:08:21 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
May 22, 2011 7:08:21 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 22, 2011 7:08:21 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 22, 2011 7:08:21 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
May 22, 2011 7:08:21 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 22, 2011 7:08:22 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Bear, please follow what Bear said..
@Topic: Still i am not convinced, i think, it is going to Catch block and then finally block.. Are you sure, the sysout in catch block was not printed.. Also, can you put sysouts in your code again, and post the relevant server logs..
 
Nav een
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the new code with sysouts :

And here is the stack :
before creation of session factory
May 23, 2011 2:22:56 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
May 23, 2011 2:22:56 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 23, 2011 2:22:56 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
May 23, 2011 2:22:56 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 23, 2011 2:22:56 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
May 23, 2011 2:22:56 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
May 23, 2011 2:22:56 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : tracker.hbm.xml
May 23, 2011 2:22:56 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: org.nav.tracker.hdto.JournalDTO -> JOURNAL_MAS
May 23, 2011 2:22:56 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
May 23, 2011 2:22:57 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 23, 2011 2:22:57 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
May 23, 2011 2:22:57 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
May 23, 2011 2:22:57 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/trackerdb
May 23, 2011 2:22:57 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.5.11
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.16 ( Revision: ${bzr.revision-id} )
May 23, 2011 2:22:57 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
May 23, 2011 2:22:57 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
May 23, 2011 2:22:57 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 23, 2011 2:22:57 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 23, 2011 2:22:57 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
May 23, 2011 2:22:58 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 23, 2011 2:22:58 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
after creation of session factory
in finally block


I thought some problem must be there with the jar file(hibernate3) i used and replaced it with hibernate 2 jar file. Still facing the same problem.
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the list of jar files you are deploying?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I thought some problem must be there with the jar file(hibernate3) i used and replaced it with hibernate 2 jar file. Still facing the same problem.


There is no problem with Hibernate3, but if you've swapped back to Hibernate2 (and that is all you have changed) you've certainly created a problem for yourself.

Reading your output the code you have posted is not the code you are running. There is no stack trace, and there is no way to jump from your try block to your finally block without showing this.
 
Nav een
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everyone for the response. It was because i didnt add jta.jar file. But, it is suppressing the class not found exception somehow withut letting it print on console. When i turn dev mode "on" in struts, it gave the exception on web page.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic