1

I'm learning Java EE and Hibernate, and I've run into the following problem:

I've created a Dynamic Web Project in Eclipse, I've converted it into a MAVEN project, added the mysql-connector-java and the hibernate-core dependencies to the pom.xml. I've added a servlet, and in the doGet method, I've tried to initialize the sessionfactory to create the tables. I'm using tomcat.

When I'm making a request to the servlet I'm getting the following exception:

org.hibernate.HibernateException: Dialect class not found:   org.hibernate.dialect.MYSQLDialect
 org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:77)
org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:65)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:146)
org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1818)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1776)
hu.adamsan.testhibernate.TestHibernate.doGet(TestHibernate.java:74)

pom.xml:

dependencies>
    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.6.Final</version>
        </dependency>
</dependencies>

I've tried to look into the Maven Dependencies, org.hibernate.dialect.MySQLDialect.class is in there, in the location: getServletContext().getRealPath(".") ->E:\eclips_jee\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestHibernateWeb\ , in the WEB-INF\lib directory, there is hibernate-core-4.2.6.Final.jar, when I opened it with 7zip, I could find inside the org/hibernate/dialect/MySQL5Dialect.class.

What am I missing? I really have no idea.

doGet method:

    PrintWriter w = response.getWriter();
    w.println("Testing hibernate<br/>");
    w.println(getServletContext().getRealPath(".")+"<br/>");

    Configuration config;
    ServiceRegistry registry;
    SessionFactory factory;     
    config = new Configuration().addAnnotatedClass(Modell.class);       
    Properties props = getProperties();     
    props.setProperty(Environment.HBM2DDL_AUTO, "create");      
    config.setProperties(props);        
    registry = new ServiceRegistryBuilder().applySettings(props).buildServiceRegistry();        
    factory = config.buildSessionFactory(registry);     
    factory.close();

3 Answers 3

5

The answer is in the question. You've found MySQLDialect and MySQL5Dialect in your jar files, but your configuration file tries to use MYSQLDialect. Java is case-sensitive.

Sign up to request clarification or add additional context in comments.

1 Comment

So, basically, I've typed big 'y' instead of small 'y'. I'm embarrassed.
2

I'm puting this because the above answer wasn't accurate for me, In my case I'm using Intellij IDEA While working with Hibernate dependency I was over configuring the pom dependency with a type (pom type) My solution is to remove that type.

<!--        Hibernate JPA dependency -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.6.3.Final</version>
        <type>pom</type>
    </dependency>

The working version Is :

<!--        Hibernate JPA dependency -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.6.3.Final</version>
    </dependency>

NO POM TYPE

Which allowed to make ride of the following bug :

java.lang.TypeNotPresentException: Type org.hibernate.SessionFactory not present that generally was blocking the resolve of the following property <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> and thus while doing the setup of hibernate session factory under the spring framework

Comments

0
<!--        Hibernate JPA dependency -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.6.3.Final</version>
    </dependency>

with pom its not working <type>pom</type>

1 Comment

Your Hibernate JPA dependency is identical to the "working version" from this answer by JAMAL EDDINE ELIDRISSI Yasser to this question. Did you mean to ask an additional, followup question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.