Reputation: 31212
i am new to hibernate. when i instantiate the session factory, i get the error
INFO: HHH000206: hibernate.properties not found
but hibernate.cfg.xml is at the root of src.
here is how i try to instantiate it:
SessionFactory hbrntFctry;
Session rslt = null;
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry();
try
{
hbrntFctry = new Configuration().configure().buildSessionFactory(serviceRegistry);
rslt = hbrntFctry.openSession();
}
catch (Throwable ex)
{
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
but then it says:
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 4 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'. at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:120) at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:69) at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:162) at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:147) at com.foampile.collect.UsgsRetriever.openHibernateSession(UsgsRetriever.java:250) at com.foampile.collect.UsgsRetriever.getStateGauges(UsgsRetriever.java:78) at com.foampile.base.MainApp.main(MainApp.java:22) Caused by: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 26; cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.] at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:419) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:356) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:326) at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:108) ... 6 more Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 26; cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1897) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:737) at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:564) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:86) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:232) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:166) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:354) ... 8 more
here is my cfg file:
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration">
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">jdbc:mysql://localhost/foampile</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- List of XML mapping files -->
<mapping resource="SiteRecord.hbm.xml"/>
</session-factory>
Upvotes: 1
Views: 5192
Reputation: 721
There is an error in your hibernate.cfg.xml file. </hibernate-configuration>
is missing.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
...
</session-factory>
</hibernate-configuration>
Upvotes: 4