-->
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: Hibernate swallowing exceptions during buildSessionFactory
PostPosted: Sun Dec 24, 2006 6:43 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
I am calling
Code:
            try {
                this.sFactory = getConfiguration().buildSessionFactory();
                int x = 5;
                x++;
            }
            catch (Throwable ex) {
                ex.printStackTrace();
                throw new ConnectionRefusedException(ex);
            }


The network cable is unplugged so hibernate can not connect. So it prints a stacktrace. But its not happening in my catch clause. Instead hibernate is swallowing the exception and not sending anything to my catch.

Is there a way to get hibernate to not swallow the copnnection exception?

org.hibernate.exception.JDBCConnectionException: Cannot open connection


Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 01, 2007 11:59 am 
Newbie

Joined: Mon Dec 25, 2006 3:14 pm
Posts: 18
> So it prints a stacktrace

From where this trace is printed? not from ex.printStackTrace()?
The api says, it throws HibernateException, catch it and throw it outside accordingly.

http://www.hibernate.org/hib_docs/v3/ap ... onFactory()


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 11:29 am 
Newbie

Joined: Mon Jan 01, 2007 10:37 am
Posts: 3
ajay516 wrote:
> So it prints a stacktrace

From where this trace is printed? not from ex.printStackTrace()?
The api says, it throws HibernateException, catch it and throw it outside accordingly.

http://www.hibernate.org/hib_docs/v3/ap ... onFactory()


I have exactly the same problem.

Code:
Configuration c = Main.configuration[tabIndex].configure();
try {
  Main.sessionFactory[tabIndex] = c.buildSessionFactory();            
}
catch (Exception ex) {
  int test = 1;
}


Code never reaches line with test variable, even though there is no database connection and exceptions are thrown.


SEVERE: could not get database metadata
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2592)
at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at deplanner.Controller.createSessionFactory(Controller.java:510)
at deplanner.Controller.connect(Controller.java:201)
at views.cards.ConnectionViewCard.buttonToggleConnectionStateWidgetSelected(ConnectionViewCard.java:466)
at views.cards.ConnectionViewCard.access$1(ConnectionViewCard.java:461)
at views.cards.ConnectionViewCard$2.widgetSelected(ConnectionViewCard.java:181)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at deplanner.Controller.createMainWindow(Controller.java:114)
at deplanner.Main.main(Main.java:64)


** END NESTED EXCEPTION **



Last packet sent to the server was 20 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2658)
at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at deplanner.Controller.createSessionFactory(Controller.java:510)
at deplanner.Controller.connect(Controller.java:201)
at views.cards.ConnectionViewCard.buttonToggleConnectionStateWidgetSelected(ConnectionViewCard.java:466)
at views.cards.ConnectionViewCard.access$1(ConnectionViewCard.java:461)
at views.cards.ConnectionViewCard$2.widgetSelected(ConnectionViewCard.java:181)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at deplanner.Controller.createMainWindow(Controller.java:114)
at deplanner.Main.main(Main.java:64)
2007-01-03 16:19:39 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: could not complete schema update
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2592)
at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at deplanner.Controller.createSessionFactory(Controller.java:510)
at deplanner.Controller.connect(Controller.java:201)
at views.cards.ConnectionViewCard.buttonToggleConnectionStateWidgetSelected(ConnectionViewCard.java:466)
at views.cards.ConnectionViewCard.access$1(ConnectionViewCard.java:461)
at views.cards.ConnectionViewCard$2.widgetSelected(ConnectionViewCard.java:181)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at deplanner.Controller.createMainWindow(Controller.java:114)
at deplanner.Main.main(Main.java:64)


** END NESTED EXCEPTION **



Last packet sent to the server was 20 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2658)
at com.mysql.jdbc.Connection.<init>(Connection.java:1509)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at deplanner.Controller.createSessionFactory(Controller.java:510)
at deplanner.Controller.connect(Controller.java:201)
at views.cards.ConnectionViewCard.buttonToggleConnectionStateWidgetSelected(ConnectionViewCard.java:466)
at views.cards.ConnectionViewCard.access$1(ConnectionViewCard.java:461)
at views.cards.ConnectionViewCard$2.widgetSelected(ConnectionViewCard.java:181)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at deplanner.Controller.createMainWindow(Controller.java:114)
at deplanner.Main.main(Main.java:64)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 7:01 pm 
Newbie

Joined: Tue Sep 26, 2006 1:43 pm
Posts: 6
Exactly the same problem.
No Exceptions in the try/catch block.

Nobody knows why??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 7:52 pm 
Newbie

Joined: Tue Sep 26, 2006 1:43 pm
Posts: 6
It looks like I've found the answer here:
http://opensource.atlassian.com/project ... 3?page=all


So I suppose the workaround could be something like this
(doing someting with our Factory):

sessionFactory = configuration.buildSessionFactory();
sessionFactory.openSession().beginTransaction().rollback();

PS
I think the documentation
http://www.hibernate.org/hib_docs/v3/ap ... onFactory()
must have explained the problem in more details.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 1:32 am 
Newbie

Joined: Mon Dec 25, 2006 3:14 pm
Posts: 18
AFIK, buildSessionFactory doesn't try to connect to database. If there is connection failure, then you should expect that error to
arise when you run a query


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:30 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
ajay516 wrote:
AFIK, buildSessionFactory doesn't try to connect to database. If there is connection failure, then you should expect that error to
arise when you run a query


It does try to connect. If the connection fails though, it tries to act like it never happened... The exception stack trace below is from the hibernate logs. the method buildSessionFactory does not throw an exception up to my program when this happens. I guess the general strategy is that I should not care about building the session factory, and only care about what happens with opened sessions.

Code:
INFO: Using Hibernate built-in connection pool (not for production use!)
Jan 22, 2007 1:26:36 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jan 22, 2007 1:26:36 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Jan 22, 2007 1:26:36 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:3333/db1
Jan 22, 2007 1:26:36 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=postgres}
Jan 22, 2007 1:26:37 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
   at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:122)
   at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
   at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:117)
   at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
   at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
   at org.postgresql.Driver.connect(Driver.java:235)
   at java.sql.DriverManager.getConnection(DriverManager.java:525)
   at java.sql.DriverManager.getConnection(DriverManager.java:140)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
   at com.rgdsft.hibernate.core.models.HibernateManager.connect(HibernateManager.java:284)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 23, 2007 2:42 am 
Newbie

Joined: Tue Sep 26, 2006 1:43 pm
Posts: 6
One more nice thing is C3PO.
If it is turned on no exceptions again :)

So I am doing this:
1. buildFactrory.
2. Open session.
3. Turn on C3PO.
4. buildFactory again

Looks ugly...


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.