JPA error with Mysql 8

Asked

Viewed 1,238 times

1

Hello,

After updating my database, my application has been presenting exceptions, like java.sql.Sqlsyntaxerrorexception.

The class below is the one he complains about, saying it doesn’t 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>

Reinforcing, that started this problem when migrating to Mysql 8, in previous versions works normally (tested with version 5.7).

I also note that I updated mysql-Connector, tried 8.0.11 and 8.0.12 versions of jar.

I’m using Windows 10.

Tables are created all in minute letters, even if Table name is capitalized.

When he launches Exception, he says: Table 'Elysium.store' does not exist.

I will be very grateful to anyone who helps me to solve this problem, because it is taking me seriously.. rs.

Thank you!

  • Was database created before running? JPA only creates tables, database does not.

1 answer

4


You can start informing 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 is you check if you have any database that has the table shop. Other database than Elysium. If you have to exclude.

That settled it for me.

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

  • Hello Victor... I did the test, trying to declare Entity within persistence.xml and it didn’t work. About deleting other Databases, I will test and inform, because there really has another database with the table store created.

  • You have deleted the other database or table shop that belongs to the same?

  • If you do not want to delete the other database, the solution would be to change the name of this Entity of @Table(name="Loja") for `@Table(name="store") for example. Or any other name than Store. I edited my answer saying this.

  • Thanks Antonio! You decided even dropping the other database. Unfortunately, I can’t change the name, the project is big, has relationships and everything. I hope this is a bug of this version of Mysql, because it doesn’t fit this.. hehe. Because data1.nameTable is different from data2.nameTable.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.