-->
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.  [ 5 posts ] 
Author Message
 Post subject: uncatchable Exception in buildSessionFactory
PostPosted: Fri Sep 30, 2005 6:29 am 
Newbie

Joined: Wed Sep 14, 2005 5:13 pm
Posts: 13
hi!

when you build a SessionFactory for a Database that does not exist,
an exception is thrown and logged.
however, i can NOT catch that exception.
what am i doing wrong?

my code:

try {
Configuration cfg = HibernateSessionPool.buildConfiguration(ds);
cfg.setProperty("hibernate.hbm2ddl.auto","create");
SessionFactory sf = cfg.buildSessionFactory();
} catch (Exception ex) {
// Make sure you log the exception, as it might be swallowed
logger.severe("Initial SessionFactory creation failed.");
throw new ExceptionInInitializerError(ex);
}

the stack trace says the exception is thrown in the last line of the try
block. however, the catch block is never entered. i have
no chance to catch the exception...

any clue?


Hibernate version:
3.0.5

Full stack trace of any exception that occurs:
INFO - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/xx
INFO - connection properties: {user=xx, password=****}
ERROR - schema export unsuccessful
java.sql.SQLException: Unknown database 'xx'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:770)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3641)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1175)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2544)
at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
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.SchemaExport$ProviderConnectionHelper.getConnection(SchemaExport.java:432)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:264)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at net.bitalchemy.omnitheca.persistence.StorageTools.exportSchema(StorageTools.java:51)

Name and version of the database you are using:
MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 8:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hbm2ddl.auto swallows any exceptions to allow your test app to continue.

If you want to catch the exception then call schemaexport manually via code.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: exception still swallowed
PostPosted: Sun Nov 20, 2005 5:27 am 
Newbie

Joined: Wed Sep 14, 2005 5:13 pm
Posts: 13
hi!

i have the same problem again.
i called schemaexport manually, not through hbm2ddl.
in my configuration, i never set hbm2ddl to any value.

however, an exception is still logged in the console but i cannot
catch it in code.

i do:

SchemaExport se = new SchemaExport(cfg);
se.create(false, true);

and get a
2005-11-20 10:18:58,265 ERROR SchemaExport:schema export unsuccessful
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:140)

SchemaExport.create is declared void, so i can't get any info out of it.


do i have to explicity set anything else in my config
in order to make exceptions catchable?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 6:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
schemaexport.getExceptions()

or

schemeexport.setHaltOnError()

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: thanks!
PostPosted: Sun Nov 20, 2005 7:18 am 
Newbie

Joined: Wed Sep 14, 2005 5:13 pm
Posts: 13
thank you very much for the really quick reply!

i'll try these.

i see you're on the hibernate team.
i suppose you have a good reason for not throwing the exception...
anyway, it would be helpful if you displayed a little note
along with the stacktrace of the exception that says how it
could still be caught or received later.

cheers again


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.