-->
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: No Exception from Persistence.createEntityManagerFactory(..)
PostPosted: Fri Mar 05, 2010 5:53 am 
Newbie

Joined: Thu Sep 18, 2008 8:48 am
Posts: 3
Location: berlin
Hi!
I'm using JPA with Hibernate.
Calling Persistence.createEntityManagerFactory(..) succeeds even though the data source is not available, i.e. my database is down.
The method does not throw any exceptions and it doesn't even return null. Is this correct behavior? How can I detect the failure?
Thank you in advance for any hints!


Top
 Profile  
 
 Post subject: Re: No Exception from Persistence.createEntityManagerFactory(..)
PostPosted: Fri Mar 05, 2010 6:07 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Is this correct behavior?

YES, Hibernate's behavior is lazy.
Hibernate always tries to obtain a connection as latest as possible.
Quote:
How can I detect the failure?


Some JDBC DataSources/Resource Pools implementations such as C3P0 provide configuration properties
which test the availibility of the database.
If your DataSources/Resource Pools implementation doesn't provide such option,
you must get a connection manually in order to check the database avalibility.


Top
 Profile  
 
 Post subject: Re: No Exception from Persistence.createEntityManagerFactory(..)
PostPosted: Fri Mar 05, 2010 6:30 am 
Newbie

Joined: Thu Sep 18, 2008 8:48 am
Posts: 3
Location: berlin
OK, thanks! I'm not too excited about this behavior though.
I now see there even is a warning:
Code:
[WARN ] Could not obtain connection to query metadata   @org.jboss.slf4j.JBossLoggerAdapter.warn
java.sql.SQLNonTransientConnectionException: java.net.ConnectException: Fehler beim Herstellen der Verbindung zum Server localhost am Port 1527. Nachricht: Connection refused: connect.
        at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
        at org.apache.derby.jdbc.ClientDriver.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:133)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)


It would be way cooler if there was a *Hibernate* configuration parameter such as hibernate.session.failfast=true.


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.