I have the following bit of code:
Code:
package models.dao;
import general.Functions;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.cfg.Configuration;
import java.io.File;
/**
* This class has been automatically generated by Hibernate Synchronizer.
* For more information or documentation, visit The Hibernate Synchronizer page
* at http://www.binamics.com/hibernatesync or contact Joe Hudson at joe@binamics.com.
*/
public class _RootDAO extends models.base._BaseRootDAO {
public static String configFile;
public _RootDAO() { }
public Class getReferenceClass() { return java.lang.Object.class; }
public void startup(String configFileName) throws HibernateException {
setConfigurationFileName(configFileName);
if (null == configFileName && sessionFactoryMap.size() > 0) return;
else if (null != sessionFactoryMap.get(configFileName)) return;
else {
Configuration cfg = new Configuration();
if (null == configFileName) {
cfg.configure();
} else {
File file = new File(configFileName);
cfg.addDirectory(new File(file.getParent() + File.separator + "somesubdir" + File.separator + "models"));
cfg.configure(file); //Fails Here!
}
setSessionFactory(configFileName, cfg.buildSessionFactory());
}
}
public void setConfigurationFileName(String configFileName) { configFile = configFileName; }
public String getConfigurationFileName() { return configFile; }
}
I call startup("C:\Work\somedir\hibernate.cfg.xml"). It sucessfully adds all of the classes in the models directory (C:\work\somedir\somesubdir\models). However, when it tries to parse the hibernate.cfg.xml file it throw an error. I'm 90% sure this error is coming from the fact that I do not have any mappings in the hibernate.cfg.xml file itself - they should have been done when I called configuration.addDirectory(dir). Is there a way around this? It seems to me that you should not have to require any mappings to occur in the hibernate.cfg.xml file as long as they are added elsewhere. Thanks in advance for any help.
Below is some debug information that might be useful:
Hibernate version: 2.1.8
Mapping documents:Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://111.111.111.111:3306/somedb</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">hibernate</property>
<property name="hibernate.connection.password">hibernate</property>
<!-- DBCP connection pooling options -->
<property name="hibernate.dbcp.maxWait">3000</property>
<property name="hibernate.dbcp.maxIdle">100</property>
<property name="hibernate.dbcp.maxActive">10</property>
<property name="hibernate.dbcp.autoReconnectForPool">true</property>
<property name="hibernate.dbcp.autoReconnect">true</property>
<!-- dialect for MySQL -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
Full stack trace of any exception that occurs:Code:
net.sf.hibernate.HibernateException: problem parsing configurationC:\Work\somedir\hibernate.cfg.xml
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:972)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:945)
at models.dao._RootDAO.startup(_RootDAO.java:36)
at ObjectInterface.initialize(ObjectInterface.java:28)
at tests.Test6.main(Test6.java:25)
Caused by: net.sf.hibernate.MappingException: invalid configuration
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:968)
... 4 more
Caused by: org.xml.sax.SAXParseException: Element "session-factory" requires additional elements.
at org.apache.crimson.parser.Parser2.error(Unknown Source)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.done(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.content(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:967)
... 4 more
Exception in thread "main"