-->
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: Session Problem
PostPosted: Tue Sep 09, 2008 12:30 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
Hi All,
I'm having some problems with function session.openSession()
It doesn't open any session!?

Here is the code I have at the moment:
The currentSession() is called from listUser() function.


public static Session currentSession() throws HibernateException {
Session s = session.get();
//Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession(); <-- here is the problem...
session.set(s);
}
return s;
}


public static List<user> listUser(){
Session session = null;
Transaction tx = null;

try {
session = currentSession(); <-------it always jumps to" finally" closing the session?!
tx = session.beginTransaction();
List list = session.createQuery("from user").list();
tx.commit();
return list;
} catch (RuntimeException ex) {
if (tx != null) {
tx.rollback();
}
throw ex;
} finally {
userUtil.closeSession();
}
}



What seems to be a problem..... Any ideas?
The sessionFactory.openSession(); always fails!
Thanks
Greg.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 1:44 pm 
Newbie

Joined: Sat Aug 23, 2008 9:10 am
Posts: 5
private static final SessionFactory sessionFactory;

private static final ThreadLocal threadSession = new ThreadLocal();

public static Session currentSession() throws NestedRuntimeException {
Session session = (Session) threadSession.get();
try {
if (session == null) {
session = sessionFactory.openSession();
threadSession.set(session);
}
} catch(HibernateException e) {
throw new NestedRuntimeException("There was a problem retrieving the current session",e);
}
return session;
}


p/s: pls provide credit if this response help you


Top
 Profile  
 
 Post subject: Session Problem
PostPosted: Tue Sep 09, 2008 2:30 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
Thanks jim_theory but it still doesn't work.
I can't figure this out.....
I can post the exception dump if that helps.
Let me know...
Thanks


Top
 Profile  
 
 Post subject: Session Problem
PostPosted: Tue Sep 09, 2008 5:03 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
Does it have anything to do with privileges?
I'm not running this example as an admin.... just a simple user that doesn't have too many privileges.
Can this cause some kind of problem with opening session?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 8:28 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Is there any chance that you might have more success with getSession as opposed to openSession?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 12:12 am 
Newbie

Joined: Sat Aug 23, 2008 9:10 am
Posts: 5
try post your exception


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 12:51 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
INFO: connection properties: {user=sa, password=****}
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: socket creation error
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
at my.userUtil.<clinit>(userUtil.java:16)
at org.apache.jsp.listUser_jsp._jspService(listUser_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Sep 10, 2008 9:37:03 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Sep 10, 2008 9:37:03 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Sep 10, 2008 9:37:03 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Sep 10, 2008 9:37:03 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Sep 10, 2008 9:37:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: info
Sep 10, 2008 9:37:04 AM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Bound factory to JNDI name: info
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: InitialContext did not implement EventContext
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
Sep 10, 2008 9:37:04 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:hsqldb:hsql://localhost/xdb
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
INFO: Unbinding factory from JNDI name: info
Sep 10, 2008 9:37:04 AM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
INFO: Unbound factory from JNDI name: info
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
Sep 10, 2008 9:37:04 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:hsqldb:hsql://localhost/xdb
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
INFO: Unbinding factory from JNDI name: info
Sep 10, 2008 9:37:04 AM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Sep 10, 2008 9:37:04 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
WARNING: Could not unbind factory from JNDI
javax.naming.NameNotFoundException: Name info is not bound in this Context
at org.apache.naming.NamingContext.unbind(NamingContext.java:254)
at org.apache.naming.NamingContext.unbind(NamingContext.java:282)
at org.apache.naming.SelectorContext.unbind(SelectorContext.java:241)
at javax.naming.InitialContext.unbind(InitialContext.java:416)
at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:116)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:806)
at my.userUtil.listUser(userUtil.java:59)
at org.apache.jsp.listUser_jsp._jspService(listUser_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Sep 10, 2008 9:37:05 AM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
Sep 10, 2008 9:37:05 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:hsqldb:hsql://localhost/xdb
Sep 10, 2008 9:37:05 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
INFO: Unbinding factory from JNDI name: info
Sep 10, 2008 9:37:05 AM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Sep 10, 2008 9:37:05 AM org.hibernate.impl.SessionFactoryObjectFactory removeInstance
WARNING: Could not unbind factory from JNDI
javax.naming.NameNotFoundException: Name info is not bound in this Context
at org.apache.naming.NamingContext.unbind(NamingContext.java:254)
at org.apache.naming.NamingContext.unbind(NamingContext.java:282)
at org.apache.naming.SelectorContext.unbind(SelectorContext.java:241)
at javax.naming.InitialContext.unbind(InitialContext.java:416)
at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:116)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:806)
at my.userUtil.listUser(userUtil.java:59)
at org.apache.jsp.listUser_jsp._jspService(listUser_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)



Ok That's all there is. I hope someone can understand this.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 11:41 am 
Beginner
Beginner

Joined: Wed Oct 03, 2007 9:46 pm
Posts: 37
if i not wrong. you are not able to open a single session at all. are you connecting to the right database ? jdbc:hsqldb:hsql://localhost/xdb ?

pls check that. sql exception, like u unable to connect to db


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.