jsando wrote:
...
I ended up copying a lot of the code out of HibernatePersistence that creates and configures the AnnotationConfiguration, so that I could use that Configuration object in a call to SchemaExport. ...
This
underhand usage of
AnnotationConfiguration byHibernatePersistence hides another problem. Imagine, you set the auto-update property like this...
Code:
<property name="hibernate.hbm2ddl.auto" value="update" />
...and let javax Persistence create the factory
without having launched the database. This leads to the following stack trace:
Code:
2005-07-15 07:54:03,720 ERROR [main] org.hibernate.tool.hbm2ddl.SchemaUpdate - could not get database 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:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:118)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:981)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:182)
at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:77)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:93)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:42)
...
2005-07-15 07:54:03,720 ERROR [main] org.hibernate.tool.hbm2ddl.SchemaUpdate - could not complete schema update
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:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:118)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:981)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:182)
at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:77)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:93)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:42)
It's
printed twice - but the excpetion(s) are collected by the SchemaUpdate tool only. You have no chance to react on those troubles in common way. Or am I missing something.
This is my test code snippet, where I expect the catch()-block to be executed if something fails while factory creation:
Code:
try {
EntityManagerFactory factory;
factory = Persistence.createEntityManagerFactory("Man", null);
// factory = new HibernatePersistence().createEntityManagerFactory(map);
LOG.debug("Created instance of '" + factory.getClass() + "' as entity"
+ " manager factory.");
return factory;
}
catch (Throwable cause) {
LOG.fatal("Creating entity manager factory failed!", cause);
throw new Error(cause);
}
New JIRA issue?
Cheers,
Sormuras