This is probably something silly, but so far I haven't turned up an answer.
I'm a new Hibernate user. I've got what so far is an extremely simple program, written in Eclipse using (among other things) Hibernate Tools. (Note that I'm doing everything in Eclipse to start, to get my dev environment up and running: I haven't tackled the Ant side yet.) The Tools are successfully generating the POJO files, and the program *runs* (somewhat to my surprise -- I was expecting a crash at this point), although it's not actually doing anything to the DB.
My issue is with SchemaExport. The Eclipse Perspective can clearly see the database, because it is showing up correctly in the Hibernate Configuration view -- it shows the tables and such correctly. But when I run SchemaExport from the Hibernate Configurations View, I get a HibernateException, which at its root seems to be due to this inner exception:
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:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at org.hibernate.eclipse.console.views.SchemaExportAction$1.execute(SchemaExportAction.java:73)
The implication seems to be that there's some kind of JNDI setup I need in order to make SchemaExport work properly, but I have no idea where that would go in this case. (The app itself runs in Tomcat, but I'm not actually running the app yet, just SchemaExport within the Eclipse Tools. It seems like I need to manage the configuration of SchemaExport itself in this case, but I may be misunderstanding -- I'm coming from the .NET side of the world, so I'm extremely new to JNDI in general.)
Is there something that needs to go into the hibernate.cfg.xml to make this work? The current state of the file looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test2</property>
<property name="hibernate.connection.username">CommYou</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/commyou/Core/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Like I said, the Perspective is clearly reading this successfully, since it's showing the test2 DB right. But I'm clearly missing something about SchemaExport itself...