JPA Error with MySQL 8

1

Hello,

After updating my database, my application has been displaying exceptions of type java.sql.SQLSyntaxErrorException .

The class below is the one it complains about, saying it does not exist when hibernate tries to create it.

@Entity
@Table(name="Loja")
public class Loja {

// Omitido para facilitar a leitura

}

This is my persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
     http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

 <persistence-unit name="persistence_elysium">

   <!-- provedor/implementacao do JPA --> 
   <provider>org.hibernate.ejb.HibernatePersistence</provider>

   <properties>
      <!-- dados da conexao -->
      <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/elysium?useTimezone=true&amp;serverTimezone=UTC" />
      <property name="javax.persistence.jdbc.user" value="pegasus" />
      <property name="javax.persistence.jdbc.password" value="password" />

       <!--  propriedades do hibernate -->
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
      <property name="hibernate.show_sql" value="false" />
      <property name="hibernate.format_sql" value="false" />

      <!--  atualiza o banco, gera as tabelas se for preciso -->
      <property name="hibernate.hbm2ddl.auto" value="update" />
   </properties>
 </persistence-unit>
</persistence>

Enhancing, which started this problem when migrating to MySQL 8, in previous versions works normally (tested with version 5.7).

I also notice that I have updated mysql-connector, I tried the 8.0.11 and 8.0.12 versions of the jar.

I'm using Windows 10.

Tables are all created with lowercase letters, even if Table name is capitalized.

When it throws the exception, it says: Table 'elysium.loja' does not exist.

I will be very grateful to anyone who helps me to solve this problem, because this is getting me out of the serious .. rs.

Thank you!

    
asked by anonymous 31.08.2018 / 15:52

1 answer

3

You can start reporting to your entity in the persistence.xml file:

<persistence-unit name="persistence_elysium">

   <!-- provedor/implementacao do JPA --> 
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <!-- Aqui são listadas todas as entidade -->
   <class>pacote.Loja</class>
...

Another thing to check is if you have a database that has the store table. Another database that is not elysium . If you have to, you have to delete.

That solved for me.

If you do not want to delete the other database, the solution would be to rename this table from @Table(name="Loja") to @Table(name="store")     
31.08.2018 / 16:03