I apologize in advance for being a complete Hibernate newb, but the library I'm using for a project uses hibernate in the background for its persistence.
The library is is JBoss JBPM 3.1.4, though I'm using the library without JBoss. It's using hibernate 3.1, connecting to a MySQL db. Connection parameters in hibernate.xfg.xml are as follows:
Code:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://xxx.xxx.xxx.xxx:3306/db</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pass</property>
Everything works just fine when I run my project in Eclipse. I haven't had any connection problems since I started the project. When I export my project to a jar and run it on the command line, though, I suddenly get an exception that suggest a datasource problem.
Code:
[Apr 18 10:53:34] INFO (Configuration.java:1035) - processing association property references
[Apr 18 10:53:34] INFO (Configuration.java:1057) - processing foreign key constraints
[Apr 18 10:53:34] INFO (NamingHelper.java:26) - JNDI InitialContext properties:{}
[Apr 18 10:53:34] FATAL (DatasourceConnectionProvider.java:55) - Could not find datasource: java:/DefaultDS
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:1
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:5
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1152)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:91
at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:76)
at org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:80)
at org.jbpm.persistence.db.DbPersistenceService.getGraphSession(DbPersistenceService.java:234)
at org.jbpm.JbpmContext.getGraphSession(JbpmContext.java:539)
at main.PmobileDriver.updateApproval(PmobileDriver.java:78)
at main.PmobileDriver.main(PmobileDriver.java:36)
Exception in thread "main" org.hibernate.HibernateException: Could not find datasource
Output from the same spot when it runs successfully in eclipse:
Code:
[Apr 18 10:49:03] INFO (DriverManagerConnectionProvider.java:41) - Using Hibernate built-in connection pool (not for production use!)
[Apr 18 10:49:03] INFO (DriverManagerConnectionProvider.java:42) - Hibernate connection pool size: 20
[Apr 18 10:49:03] INFO (DriverManagerConnectionProvider.java:45) - autocommit mode: false
[Apr 18 10:49:03] INFO (DriverManagerConnectionProvider.java:80) - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://xxx.xxx.xxx.xxx:3306/db
[Apr 18 10:49:03] INFO (DriverManagerConnectionProvider.java:86) - connection properties: {user=user, password=****}
[Apr 18 10:49:03] INFO (SettingsFactory.java:77) - RDBMS: MySQL, version: 5.0.22
[Apr 18 10:49:03] INFO (SettingsFactory.java:78) - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.7 ( $Date: 2005/01/25 19:11:41 $, $Revision: 1.27.4.54 $ )
[Apr 18 10:49:03] INFO (Dialect.java:103) - Using dialect: org.hibernate.dialect.MySQLDialect
To my untrained eye it looks like it could be a configuration problem, since it seems to be either not finding the datasource that's configured for the project or trying to use the wrong datasource.
Any suggestions would be greatly appreciated.