I tried to test whether the hibernate configuration is working properly. I tried but I got an error:
INFO: HHH000206: hibernate.properties not found
<
I think you are missing some hibernate libs (maybe hibernate-tools.jar
I guess). So please check it.
Anyway, I saw you using the hibernate annotations, so please try this code and see what happen with error properties not found.
try {
AnnotationConfiguration configuration = new AnnotationConfiguration();
sessionFactory = configuration.configure().buildSessionFactory();
}
Your problem is creation session Factory for your application it happening in HibernateUtilities
class , the reason may be due to , you cannot create a sessionfactory by sessionRegistry
create it by hibernate Configuration class, because you registered your configuration in hibernate.cfg.xml
Just Replace the following code in HibernateUtilities class
`sessionFactory = configuration.buildSessionFactory(serviceRegistry);`
to
`sessionFactory = configuration.buildSessionFactory();`
In my case, I was running the Hibernate 5 with JPA annotations on tomcat and stop working when I changed to glassfish 4.1
The error:
hibernate.properties not found
Make sure: src/main/resources/hibernate.cfg.xml exists
And if you only have the dependency of hibernate-core, I was using hibernate-annotations and hibernate-common-annotations and it was creating conflict. The hibernate 5 doesnt need these two, I had read somewhere.Try to remove ;)
After that a new error appears:
java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
The reason was the oldest jboss-logging.jar at: "YOUR_GLASSFISH_FOLDER/glassfish/modules"
Why? The hibernate 5 has dependency with the newest version of jboss-logging, and the glassfish 4 uses the oldest version even if you declare inside your POM file the newest version. Actually I'm using:
org.jboss.logging jboss-logging 3.3.0.Final
Then I downloaded it and replace the old .jar inside the modules path and it back to work, I spent 2 days trying to solve that and I hope it helps some future issues =D
I used this link to help me: https://medium.com/@mertcal/using-hibernate-5-on-payara-cc242212a5d6#.npq2hdprz
Another solution, in my case, could be back to the last Hibernate 4 version (4.3.11.Final) but it is already too old in my opinion
session-factory is a special tag in hibernate it's have no any name so, You can change your code session-factory name="" to session-factory and try to run.
The configuration files must be placed in the classpath. Make Sure that the hibernate.cfg.xml is in class-path. As your program is console program, u need to place that hibernate.cfg.xml in src folder. If u have placed it in other folder than specify it in Confingure.configure(fileName);
And as answered By Mr.Kark u have to delete following lines
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
That's only an INFO message telling that you don't have a hibernate.properties
file. This property file is not mandatory and so it's not what prevents your application from working.
If you want to know what caused the SessionFactory
creation failure, you need to change your catch block to:
catch(HibernateException exception){
System.out.println("Problem creating session factory");
exception.printStackTrace();
}
You should use a logging framework instead.