JPA/Hibernate works with Postgresql, but not with Mysql

11,001

Solution 1

You missing configuration hibernate dialect for PostgreSQL:

<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

EDIT:

You have miss spelling in configuration:

<property name="hiberante.connection.url" value="jdbc:mysql://localhost:3306/GoOut2"/>

should be

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

Is hibernate, but not hiberante.

Solution 2

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/demo</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
Share:
11,001
Vojtěch
Author by

Vojtěch

Updated on June 04, 2022

Comments

  • Vojtěch
    Vojtěch almost 2 years

    I am trying to replace PostgreSQL in my application with MySQL. I thought that it should be sufficient to replace the <properties> in persistence.xml file:

    PostgreSQL:

    <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/postgres"/>
    <property name="hibernate.connection.username" value=""/>
    <property name="hibernate.connection.password" value=""/>
    <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
    <property name="hibernate.show_sql" value="true"/>
    

    MySQL:

    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hiberante.connection.url" value="jdbc:mysql://localhost:3306/GoOut2"/>
    <property name="hibernate.connection.username" value=""/>
    <property name="hibernate.connection.password" value=""/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    

    But with this replacement, I amg getting

    java.lang.UnsupportedOperationException: The application must supply JDBC connections
    

    I am not sure what I am doing wrong, I just hoped that the replacement would be straightforward. In PostgreSQL, everything works correctly.

    Persistence.xml: https://gist.github.com/2252443

    applicationContext.xml: https://gist.github.com/2252463

    exception: https://gist.github.com/2252487

    Thanks!

    EDIT: I remove username and password from the given code intentionally.

    • araqnid
      araqnid about 12 years
      can you post the startup messages for the session factory as well?
    • Sinisha Mihajlovski
      Sinisha Mihajlovski about 12 years
      can you connect from mysql workbench with the given credential information?
  • Vojtěch
    Vojtěch about 12 years
    I just forgot to add it to the example, but my problem is not PostgreSQL, byt MySQL.