I also just switched from 3.0 to 4.0, I assume 3 reasons to use the following DTDs
ACTUAL USE IN THIS CASE
Make sure you don't have the old version 3.0 in the way, otherwise you might see this exception.
Possible reason 1
For hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
And for hbm files
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
Works well for me.
Possible reason 2
You have misspelt <hibernate-mapping> in your hbm file.
Edit:
I use a mixed configuration of both software and cfg files. When I tried to use all the programs, this did not work for me. I also did not get much help from SO. But below worked for me.
try { String connection = "jdbc:mysql://" + Globals.DBSERVER.trim() + "/myDB?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; log.debug("Connection URL "+connection) ; Configuration configuration = new Configuration(); configuration .setProperty("hibernate.connection.url", connection) .setProperty("hibernate.connection.username", Globals.DB_USER_NAME.trim()) .setProperty("hibernate.connection.password", Globals.DB_PASSWORD.trim()) ; configuration.configure(); sessionFactory = configuration .buildSessionFactory(new ServiceRegistryBuilder() .applySettings(configuration.getProperties()).buildServiceRegistry()); } catch (Exception e) { log.fatal("Unable to create SessionFactory for Hibernate"); log.fatal(e.getMessage()); log.fatal(e); e.printStackTrace(); }
My question that helped me fix this.
General advice
Switching to all programs is a bad idea. Since there are many program materials that need to be added from a column to a variable mapping in a variable type. This will be a debugging nightmare. I suggest doing non-software things for things that you can do without software. For me, I just needed to get the user password from the cmd line so that I could deploy the product to any server. So I just made this program.
source share