Remove deprecation from Configuration until after new metamodel completely in place

Description

Decided to leave in place for Ejb3Configuration since JPA bootstrapping was always the recommended and supported mechanism for JPA use cases.

Environment

None

Activity

Show:
Steve Ebersole
August 30, 2011, 1:39 AM

The work for was committed as part of

Vladimir Nicolici
March 30, 2012, 3:42 PM

Can you also remove the deprecation from the Configuration.buildSessionFactory() method? It's very annoying, and I lost a few hours searching for the proper way to do it, and I still didn't find it. This, for example, doesn't work:

ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
serviceRegistryBuilder.configure("hibernate-connection.cfg.xml");
ServiceRegistry serviceRegistry = serviceRegistryBuilder.buildServiceRegistry();
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

It gives this error:

WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
Exception in thread "main" org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

Anyway, it's even worse when I try to use the deprecated way, I'm not even able to read the configuration:

Configuration configuration = new Configuration();
configuration.configure("hibernate-connection.cfg.xml");

gives this error:

ERROR: HHH000197: Error parsing XML: hibernate-connection.cfg.xml(3) Document is invalid: no grammar found.
Mar 30, 2012 4:19:32 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error
ERROR: HHH000197: Error parsing XML: hibernate-connection.cfg.xml(3) Document root element "hibernate-configuration", must match DOCTYPE root "null".
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2008)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1925)
at DbTest.main(DbTest.java:14)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)

Even a nearly empty configuration file, like below, causes the same error:

<?xml version='1.0' encoding='utf-8'?>

<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<session-factory>

</session-factory>

</hibernate-configuration>

Not sure if relevant, but http://www.hibernate.org/xsd/hibernate-configuration does not really exist, attempting to access it using a browser gives this:

Sorry, the page you're looking for cannot be found.
Please use the Search box in the header to check that the information isn't located somewhere else.

Even the example configuration file from http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html#d5e83

gives me the same error about invalid XML grammar.

Anyway, my main issue is that the documentation still recommends the use of the deprecated method, and no alternate method is documented (or I can't find it), see:

http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html/ch02.html#hibernate-gsg-tutorial-basic-test

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-sessionfactory

Other people have the same issue:

http://www.coderanch.com/t/564214/ORM/java/Hibernate-configuration-connection-provider-or

Please note that I have about 3 years experience in using hibernate in various projects, and never had such issues until trying to use the latest version in a new project, so do not dismiss this comment as a newbie question.

I'm using Hibernate 4.1.1 in a simple "hello world" project, JDK 1.7.0_03, Eclipse Indigo SR2.

Vladimir Nicolici
April 2, 2012, 10:31 AM

After further investigation, it seems the only way to configure Hibernate 4.1.1 and obtain a working SessionFactory is to use Hibernate 3 DTD based configuration files instead of the Hibernate 4 XSD configuration files, and to use the deprecated buildSessionFactory() method instead of the recommended buildSessionFactory(serviceRegistry) method.

I found this by running the annotations example from the tutorials (http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/files/hibernate-tutorials.zip). The tutorial samples still use the deprecated method, that's why they still work.

Paul Benedict
April 9, 2014, 4:17 PM

I think we should spin off a new ticket for the "Document is invalid: no grammar found" SAX error. I am using 4.2.9 and cannot find any solution except to dump using the XSD (and revert to the DTD). Others on the internet come to the same conclusion.

Assignee

Steve Ebersole

Reporter

Steve Ebersole

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Major
Configure