view raw
G.Spansky G.Spansky - 7 months ago 40
MySQL Question

Hibernate and MySQL configuration

I have spent a few hours trying to set up my first Hibernate application and it still doesn't work.

I have WAMP Server with my MySQL Data Base called "hibernatetest". I have Project in Eclipse, which contains Hibernate library, and mysql-connector-java-5.1.18-bin.jar. I have also this classes:

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory(
new StandardServiceRegistryBuilder().build() );
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);

public static SessionFactory getSessionFactory() {
return sessionFactory;

} (contains main):

import org.hibernate.Session;

import templates.Album;

public class test {
public static void main(String[] args){
Album i = new Album();
i.setArtist("Iron Maiden");
i.setTitle("The Book of Souls");
i.setLabel("Warner Music");

Session session = HibernateUtil.getSessionFactory().getCurrentSession();


package templates;

public class Album {
private int ID;
private String title;
private String artist;
private String label;

public Album(){


public int getID() {
return ID;

public void setID(int iD) {
ID = iD;

public String getTitle() {
return title;

public void setTitle(String title) {
this.title = title;

public String getArtist() {
return artist;

public void setArtist(String artist) {
this.artist = artist;

public String getLabel() {
return label;

public void setLabel(String label) {
this.label = label;


Album.hbm.xml: link

Hibernate.cfg.xml: link


wrz 15, 2015 10:04:47 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.1.Final}
wrz 15, 2015 10:04:47 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: not found
wrz 15, 2015 10:04:47 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
wrz 15, 2015 10:04:47 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace Use namespace instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
wrz 15, 2015 10:04:48 PM <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
wrz 15, 2015 10:04:49 PM org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
wrz 15, 2015 10:04:49 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
Initial SessionFactory creation Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Exception in thread "main" java.lang.ExceptionInInitializerError
at HibernateUtil.buildSessionFactory(
at HibernateUtil.<clinit>(
at test.main(
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at HibernateUtil.buildSessionFactory(
... 2 more
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(
... 15 more

What am I doing wrong?


I had the same problem . just add your port number after localhost .in my case it is localhost:3306

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/your_db</property>