0

I'm currently developing a login and registration feature for my application, and I'm trying to connect to my MySQL database. However, I'm facing an issue where the application reports that the database is empty, even though I've confirmed that it contains dummy data.

Details:

Database Name: nutzer Table Name: users (not USERS) I've followed the necessary steps to set up the database connection and configured my JPA settings using Hibernate.

Error Message: [Tabelle "USERS" nicht gefunden (diese Datenbank ist leer)]

What I've Tried:

  • Double-checked the table name and ensured it is defined as users.
  • Verified that the database contains data using MySQL Workbench.
  • Reviewed the JPA configuration for any potential issues.

Question: What could be causing the application to not recognize the existing data in the users table? Any suggestions on how to resolve this issue would be greatly appreciated!

package de.likeherotozero;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "users", schema = "nutzer")

public class EmissionsData {
    @Id
    private Long id;
    private String country;
    private double value;

    // Getters and Setters
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getCountry() {
        return country;
    }
    public void setCountry(String country) {
        this.country = country;
    }
    public double getValue() {
        return value;
    }
    public void setValue(double value) {
        this.value = value;
    }
}

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="my-persistence-unit">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>de.likeherotozero.User</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/nutzer"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="myCorrectPassword is here"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

3
  • mysql -p -e "show tables from nutzer" at the command line says what?
    – g00se
    Commented Oct 26, 2024 at 16:40
  • +------------------+ | Tables_in_nutzer | +------------------+ | users | | usersdata | +------------------+ Commented Oct 26, 2024 at 17:40
  • mysql -p -e "select count(*) from nutzer.users" Note also that unless you are logged in to that terminal as 'root' (I hope not) then you have a different user configured in JPA
    – g00se
    Commented Oct 26, 2024 at 18:00

1 Answer 1

0

You should be aware that MySQL does not support schema. There, schema and database are synonyms. Therefore, using the schema parameter in the @Table(name = "users", schema = "nutzer") annotation is pointless. This may be the cause of the error you encountered. Try removing this parameter from the annotation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.