wake-up-neo.com

org.hibernate.tool.schema.spi.CommandAcceptanceException: Fehler beim Ausführen der DDL über die JDBC-Anweisung

Ich brauche wirklich Hilfe, die ich in allen Fragen gesucht habe, die ich bei stackoverflow gefunden habe, und nichts funktioniert. Ich habe noch nie zuvor den Winterschlaf genutzt und weiß nicht, was ich falsch mache. Ich habe Tabellen erstellt, aber mit Einfügungen habe ich Probleme. 

Ich erhalte diesen Fehler:

20-May-2017 10:53:41.085 WARN [http-nio-8080-exec-1] org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl.handleException GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
 org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.Java:67)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.Java:525)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.Java:470)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applyForeignKeys(AbstractSchemaMigrator.Java:429)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.Java:245)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.Java:110)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.Java:183)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.Java:72)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.Java:309)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.Java:445)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:710)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:726)
    at gameplatform.servlet.IndexPage.init(IndexPage.Java:46)
    at org.Apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.Java:1183)
    at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1099)
    at org.Apache.catalina.core.StandardWrapper.allocate(StandardWrapper.Java:779)
    at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:133)
    at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:96)
    at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:478)
    at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:140)
    at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:80)
    at org.Apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.Java:624)
    at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:87)
    at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:342)
    at org.Apache.coyote.http11.Http11Processor.service(Http11Processor.Java:799)
    at org.Apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.Java:66)
    at org.Apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.Java:861)
    at org.Apache.Tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.Java:1455)
    at org.Apache.Tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.Java:49)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at org.Apache.Tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.Java:61)
    at Java.lang.Thread.run(Thread.Java:745)
Caused by: Java.sql.SQLException: Cannot add foreign key constraint
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.Java:964)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3909)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.Java:2527)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.Java:2680)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.Java:2497)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.Java:2455)
    at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.Java:839)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.Java:739)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.Java:54)
    ... 32 more

das ist meine Konfigurationsdatei:

<?xml version="1.0" encoding="UTF-8"?>

<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:8889/gameplatform</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <property name="connection.pool_size">100</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL55Dialect</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>

        <mapping class="db.table.template.Permesso"/>
        <mapping class="db.table.template.PermessoTemplate"/>
        <mapping class="db.table.template.PermessoTemplateId"/>
        <mapping class="db.table.template.Template"/>
        <mapping class="db.table.template.Gruppo"/>
        <mapping class="db.table.template.Utente"/>
        <mapping class="db.table.template.Livello"/>
        <mapping class="db.table.template.Gioco"/>
        <mapping class="db.table.template.Giocare"/>
        <mapping class="db.table.template.GiocareId"/>
        <mapping class="db.table.template.Trofeo"/>
    </session-factory>
</hibernate-configuration>

das ist meine Testseite:

package gameplatform.servlet
public class TestPage extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestPage() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());

    Configuration conf = new Configuration().configure();
    Session session = conf.buildSessionFactory().getCurrentSession();
    session.beginTransaction();

    Permesso permesso = new Permesso();
    permesso.setNome("Index");
    permesso.setIndirizzo("gameplatform.op");

    Template template = new Template("slider.jsp");
    session.saveOrUpdate(template);

    PermessoTemplate permessoTemplate = new PermessoTemplate();
    permessoTemplate.setPermesso(permesso);
    permessoTemplate.setTemplate(template);
    permessoTemplate.setPriority(3);

    permesso.getPermessoTemplate().add(permessoTemplate);

    session.saveOrUpdate(permesso);

    Query query = session.createQuery("from Template template join template.permessoTemplate joinPage where joinPage.pk.permesso = 'Index' order by joinPage.priority");
    List<Template> temp = query.list();

    Iterator it = temp.iterator();
    while (it.hasNext()) { 
        Object[] obj = (Object[]) it.next();
        Template test = (Template) obj[0];
        response.getWriter().append(" " + test.getIndirizzo());          
    }

    Gruppo test = new Gruppo("Admin");
    session.saveOrUpdate(test);

    Utente user = new Utente("Romolo", "De Roma", 20, "Er Zezzo", "Prova", "tes[email protected]", 3000, 3);
    user.setGruppo(test);
    test.getUtente().add(user);
    test.getPermesso().add(permesso);

    session.saveOrUpdate(user);

    /*Recensione recensione = new Recensione();
    recensione.setDescrizione("Gioco Bello");
    recensione.setVoto(4);
    recensione.setUtente(user);

    session.saveOrUpdate(recensione);*/

    Query control = session.createQuery("from Livello");
    List<Livello> controlList = control.list();

    boolean bool = false;
    Iterator iter = controlList.iterator();
    while (iter.hasNext()) { 
        //Object[] obj = (Object[]) 
        Livello lv = (Livello) iter.next();

        if (lv.getLivello()==3 && lv.getUtente().getUsername().equals(user.getUsername())){
            bool=true;
        }
    }
    if (!bool){
        Livello livello = new Livello();
        livello.setLivello(3);
        livello.setDate(new GregorianCalendar(2017,5,20));
        livello.setUtente(user);

        session.saveOrUpdate(livello);
    }

    Gioco gioco = new Gioco();
    gioco.setNome("Zezzo");
    gioco.setDescrizione("Bel Gioco Di Merda");
    gioco.setSpecifiche("2Gb di Rom");

    Giocare giocare = new Giocare();
    giocare.setExp(3000);
    giocare.setMinuti(new Time(2000));
    giocare.setNumAccessi(30);
    giocare.setRecensione("Bello ma Brutto");
    giocare.setVoto(5);
    giocare.setUtente(user);
    giocare.setGioco(gioco);

    gioco.getGiocare().add(giocare);

    session.saveOrUpdate(gioco);

    Trofeo trofeo = new Trofeo();
    trofeo.setNome("Test");
    trofeo.setIcona("icona.jpg");
    trofeo.setObiettivo(5);
    trofeo.setGioco(gioco);
    user.getTrofeo().add(trofeo);

    session.saveOrUpdate(trofeo);

    session.getTransaction().commit();

}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
}}

das ist meine IndexPage:

package gameplatform.servlet;

    public class IndexPage extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private String pageName;
    private String[] template;

/**
 * @see HttpServlet#HttpServlet()
 */
public IndexPage() {
    super();
    // TODO Auto-generated constructor stub
}

public void init(ServletConfig config) throws ServletException {

    // TODO Auto-generated method stub
    super.init(config);
    this.pageName = getInitParameter("pageIndex");

    Configuration conf = new Configuration().configure();
    Session session = conf.buildSessionFactory().getCurrentSession();
    session.beginTransaction();

    String query = "from Template template join template.permessoTemplate joinPage where joinPage.pk.permesso = ? order by joinPage.priority";
    List execute = session.createQuery(query).setString(0, pageName).list();

    session.getTransaction().commit();

    Iterator it = execute.iterator();
    int i = 0;
    this.template = new String[execute.size()];
    while (it.hasNext()) { 
        Object[] obj = (Object[]) it.next();
        Template temp = (Template) obj[0];  ;
        this.template[i] = temp.getIndirizzo();
        i++;
    }

}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    process(request, response);
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    process(request, response);
}

private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    request.setAttribute("template", this.template);

    RequestDispatcher view = request.getRequestDispatcher("JSP/index.jsp");
    view.forward(request, response);
}}

Dies sind meine SQL-Protokolle:

    2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."giocare" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."gioco" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."gruppo" but the required 
system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."permessogruppo" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."trofeo" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."utente" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 10:53:45 70000ed64000 InnoDB: Error: Fetch of persistent statistics requested for table "gameplatform"."utentetrofeo" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-05-20 11:54:17 70000ecdc000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-05-20 11:54:46 70000ec54000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found. 
3
Andrea Perelli

problem in Ihrer Dialekt-Engine ändern Sie in Ihren Mysql-Dialekt und fügen Sie es den folgenden Zeilen hinzu

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

1
Vivek Gajbhiye

Ich hatte diese Ausnahme mit SprintBoot 2.x, durch Ändern des Dialekts wurde es behoben. Org.hibernate.tool.schema.spi.CommandAcceptanceException: Fehler beim Ausführen der DDL über die JDBC-Anweisung

Ich war mit demselben Problem konfrontiert, und was mich aus dieser Ausnahme herausführte, wurde in den folgenden Schritten veranschaulicht:

  1. <hibernate-configuration name="">-Tag in <hibernate-configuration> in der Datei hibernate.cfg.xml geändert.
  2. Nennen Sie das Verbindungs-Tag immer zusammen mit dem localhost, dem Port und dem Schemanamen oder dem Datenbanknamen wie - <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/protein_tracker</property>.

und dies macht die Ausführung ausnahmslos, es funktioniert für mich, hoffe es hilft auch ein bisschen!

0
ArifMustafa

Um genau zu sein, hat Ihr Hibernate JDBC-Treiber ein Problem, wenn Sie ein Skript (DDL) in Richtung MySQL-Datenbank ausführen. 

In dem Fehler gibt es eine richtige Erklärung: Es gibt eine Ausnahme in der SQL-Abfrage mit dem Fehler "Fremdschlüsseleinschränkung kann nicht hinzugefügt werden".

Sie haben mehrere Tabellen zugeordnet. Ich schlage daher vor, nacheinander zu gehen und zu sehen, bei welcher Tabellengenerierung der Fehler auftritt. Dies wird Ihnen helfen, den Constrain Error, den Sie haben, zu verstehen.

Das von Ihnen bereitgestellte Fehlerprotokoll ist nicht relevant, da es statistische Tabellenfehler anzeigt, die durch andere Statistiken für die Ausführung der DB-Engine ersetzt werden.

Vielen Dank

0
zhrist