0

I'm trying to deploy a Java application to WildFly that uses Hibernate with a MySQL database. However, when I run my application, I get the following error in the logs:

    alter table exam_table 
       drop 
       foreign key FKgp6h92beial8lknuhckmukak8" via JDBC [No database selected]

persistence.xml:

<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence
                                 https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
             version="3.0">

    <persistence-unit name="control" transaction-type="JTA">
        <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>

        <!-- Entity classes -->
        <class>com.to.Speciality</class>
        <class>com.to.Exam</class>
        <class>com.to.Student</class>
        <class>com.to.Session</class>

            <!-- Hibernate Provider Properties -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.use_sql_comments" value="false" />

            <!-- Connection Pooling (Optional) -->
            <property name="hibernate.connection.pool_size" value="10" />
        </properties>
    </persistence-unit>
</persistence>

standalone.xml:

<subsystem xmlns="urn:jboss:domain:datasources:7.2">
    <datasources>
        <datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:mysql://localhost:3306/examdb?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false</connection-url>
            <driver>com.mysql</driver>
            <pool>
                <min-pool-size>5</min-pool-size>
                <max-pool-size>20</max-pool-size>
            </pool>
            <security user-name="root" password="pwd"/>
            <validation>
                <check-valid-connection-sql>USE examdb; SELECT 1</check-valid-connection-sql>
                <background-validation>true</background-validation>
                <background-validation-millis>10000</background-validation-millis>
            </validation>
        </datasource>
        <drivers>
            <driver name="com.mysql" module="com.mysql">
                <driver-class>com.mysql.cj.jdbc.Driver</driver-class>
                <datasource-class>com.mysql.cj.jdbc.MysqlDataSource</datasource-class>
            </driver>
        </drivers>
    </datasources>
</subsystem>

Issue: When I try to deploy my .war file to WildFly, I encounter the following error:

GenerationTarget encountered exception accepting command : Error executing DDL "
    alter table exam_table 
       drop 
       foreign key FKgp6h92beial8lknuhckmukak8" via JDBC [No database selected]

From my understanding, it seems like Hibernate is trying to execute a DDL command, but it is not able to find the database. I've verified that examdb exists in MySQL and that the database URL is correctly set in standalone.xml.

What I've Tried:

I have confirmed that the MySQL database examdb exists. The connection URL in standalone.xml is correctly set to jdbc:mysql://localhost:3306/examdb. I’ve made sure that my JTA data source (java:jboss/datasources/MySQLDS) is correctly referenced in persistence.xml. The MySQL JDBC driver is properly configured in WildFly as a module.

Question:

What could be causing the "No database selected" error? How can I fix this issue and ensure Hibernate can correctly select the database for its DDL operations?

3
  • I sounds like the user (with the correct credentials) doesn't have permission on your examdb database.
    – danblack
    Commented Jan 17 at 9:18
  • I don't think it's a permission issue. I guess your problem is either there are no examdb on your mysql server or the tags after you put your jdbc connection string's examdb part is causing problems. After ensuring the examdb is really exist try this -> <connection-url>jdbc:mysql://localhost:3306/examdb</connection-url> Commented Jan 19 at 2:46
  • I managed to establish the connected to the database, by adding the jdbc from the admin console instead of adding it manually from standalone.xml, still couldn't figure out what was the initial issue, but it worked this way. Commented Jan 19 at 8:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.