【问题标题】:liquibase.exception.DatabaseException JHipster Frameworkliquibase.exception.DatabaseException JHipster 框架
【发布时间】:2017-11-30 21:55:20
【问题描述】:

我正在使用 JHipster 框架,并且我创建了一个带有 Blob 图像字段的子生成器的实体。在这个领域,我正在保存 SVG 文件。 表声明如下所示:

    <?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <property name="now" value="now()" dbms="h2"/>
    <property name="now" value="now()" dbms="mysql"/>
    <property name="autoIncrement" value="true"/>

    <property name="clobType" value="clob" dbms="h2"/>
    <property name="clobType" value="longtext" dbms="mysql"/>

    <property name="blobType" value="blob" dbms="h2"/>
    <property name="blobType" value="longblob" dbms="mysql"/>

    <!--
        Added the entity Pattern.
    -->
    <changeSet id="20171023230151-1" author="jhipster">
        <createTable tableName="pattern">
            <column name="id" type="bigint" autoIncrement="${autoIncrement}">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(255)">
                <constraints nullable="false" />
            </column>

            <column name="description" type="varchar(255)">
                <constraints nullable="false" />
            </column>

            <column name="pattern_icon" type="${blobType}">
                <constraints nullable="true" />
            </column>

            <column name="pattern_icon_content_type" type="varchar(255)">
                <constraints nullable="true" />
            </column>


            <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
        </createTable>
        <loadData tableName="pattern"
                  encoding="UTF-8"
                  separator=";"
                  file="config/liquibase/pattern.csv">
        </loadData>

    </changeSet>
    <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove-->
</databaseChangeLog>

在我的测试环境中,我使用 H2 作为 DB。在开发中,我正在使用 MySQL。 当我尝试运行从我或 JHIpster 创建的任何测试时,我收到一个 org.h2.jdbc.JdbcSQLException,它说,该十六进制字符串包含非十六进制字符。

所以我认为这是一个 H2 问题,我不知道如何找到解决方法。JHipster 中有没有办法分别排除 liquibase 检查以跳过这一点以使测试用例工作? 错误消息的摘录在这里:

2017-11-30 22:42:15.504  INFO 17884 --- [           main] irpd.web.rest.ParameterResourceIntTest   : Starting ParameterResourceIntTest on Yun with PID 17884 (started by Sebnem in C:\Users\Sebnem\HSR_BA\irpd)
2017-11-30 22:42:15.510  INFO 17884 --- [           main] irpd.web.rest.ParameterResourceIntTest   : No active profile set, falling back to default profiles: default
2017-11-30 22:42:23.290  INFO 17884 --- [           main] irpd.config.MetricsConfiguration         : Initializing Metrics Log reporting
2017-11-30 22:42:28.671 ERROR 17884 --- [           main] liquibase                                : classpath:config/liquibase/master.xml: config/liquibase/changelog/20171023230151_added_entity_Pattern.xml::20171023230151-1::jhipster: Change Set config/liquibase/changelog/20171023230151_added_entity_Pattern.xml::20171023230151-1::jhipster failed.  Error: Hexadezimal Zahl enthält unerlaubtes Zeichen: "<svg xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 71.87 71.87""><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id=""Ebene_2"" data-name=""Ebene 2""><g id=""Ebene_27"" data-name=""Ebene 27""><circle cx=""35.93"" cy=""35.93"" r=""19.02""/><rect class=""cls-1"" x=""0.5"" y=""0.5"" width=""70.87"" height=""70.87"" rx=""14.17"" ry=""14.17""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""12.28"" ry=""3.93"" transform=""matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28"" transform=""translate(-13.15 49.09) rotate(-60)""/><circle class=""cls-3"" cx=""35.93"" cy=""35.93"" r=""1.73""/></g></g></svg>"
Hexadecimal string contains non-hex character: "<svg xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 71.87 71.87""><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id=""Ebene_2"" data-name=""Ebene 2""><g id=""Ebene_27"" data-name=""Ebene 27""><circle cx=""35.93"" cy=""35.93"" r=""19.02""/><rect class=""cls-1"" x=""0.5"" y=""0.5"" width=""70.87"" height=""70.87"" rx=""14.17"" ry=""14.17""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""12.28"" ry=""3.93"" transform=""matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28"" transform=""translate(-13.15 49.09) rotate(-60)""/><circle class=""cls-3"" cx=""35.93"" cy=""35.93"" r=""1.73""/></g></g></svg>"; SQL statement:
INSERT INTO PUBLIC.pattern (id, name, description, pattern_icon, pattern_icon_content_type) VALUES ('1', 'Atomic Parameter', 'Atomic Parameter Description', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 71.87 71.87"><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id="Ebene_2" data-name="Ebene 2"><g id="Ebene_27" data-name="Ebene 27"><circle cx="35.93" cy="35.93" r="19.02"/><rect class="cls-1" x="0.5" y="0.5" width="70.87" height="70.87" rx="14.17" ry="14.17"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="12.28" ry="3.93" transform="matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28" transform="translate(-13.15 49.09) rotate(-60)"/><circle class="cls-3" cx="35.93" cy="35.93" r="1.73"/></g></g></svg>', 'image/svg+xml') -- ('1', 'Atomic Parameter', 'Atomic Parameter Description', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 71.87 71.87"><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id="Ebene_2" data-name="Ebene 2"><g id="Ebene_27" data-name="Ebene 27"><circle cx="35.93" cy="35.93" r="19.02"/><rect class="cls-1" x="0.5" y="0.5" width="70.87" height="70.87" rx="14.17" ry="14.17"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="12.28" ry="3.93" transform="matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28" transform="translate(-13.15 49.09) rotate(-60)"/><circle class="cls-3" cx="35.93" cy="35.93" r="1.73"/></g></g></svg>', 'image/svg+xml') [90004-196] [Failed SQL: INSERT INTO PUBLIC.pattern (id, name, description, pattern_icon, pattern_icon_content_type) VALUES ('1', 'Atomic Parameter', 'Atomic Parameter Description', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 71.87 71.87"><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id="Ebene_2" data-name="Ebene 2"><g id="Ebene_27" data-name="Ebene 27"><circle cx="35.93" cy="35.93" r="19.02"/><rect class="cls-1" x="0.5" y="0.5" width="70.87" height="70.87" rx="14.17" ry="14.17"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="12.28" ry="3.93" transform="matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)"/><ellipse class="cls-2" cx="35.93" cy="35.93" rx="3.93" ry="12.28" transform="translate(-13.15 49.09) rotate(-60)"/><circle class="cls-3" cx="35.93" cy="35.93" r="1.73"/></g></g></svg>', 'image/svg+xml']
2017-11-30 22:42:28.685  WARN 17884 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [irpd/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20171023230151_added_entity_Pattern.xml::20171023230151-1::jhipster:
     Reason: liquibase.exception.DatabaseException: Hexadezimal Zahl enthält unerlaubtes Zeichen: "<svg xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 71.87 71.87""><defs><style>.cls-1,.cls-2{fill:none;stroke-miterlimit:10;}.cls-1{stroke:#000;}.cls-2{stroke:#fff;}.cls-3{fill:#fff;}</style></defs><title>Element 14</title><g id=""Ebene_2"" data-name=""Ebene 2""><g id=""Ebene_27"" data-name=""Ebene 27""><circle cx=""35.93"" cy=""35.93"" r=""19.02""/><rect class=""cls-1"" x=""0.5"" y=""0.5"" width=""70.87"" height=""70.87"" rx=""14.17"" ry=""14.17""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""12.28"" ry=""3.93"" transform=""matrix(0.87, -0.5, 0.5, 0.87, -13.15, 22.78)""/><ellipse class=""cls-2"" cx=""35.93"" cy=""35.93"" rx=""3.93"" ry=""12.28"" transform=""translate(-13.15 49.09) rotate(-60)""/><circle class=""cls-3"" cx=""35.93"" cy=""35.93"" r=""1.73""/></g></g></svg>"

在运行 JUNIT 测试时是否可以排除此列?每当我运行 Junit 测试时,它都会在第 4 行“liquibase”处崩溃。

2017-12-01 11:13:11.601  INFO 51092 --- [           main] irpd.web.rest.AccountResourceIntTest     : Starting AccountResourceIntTest on Yun with PID 51092 (started by Sebnem in C:\Users\Sebnem\HSR_BA\irpd)
2017-12-01 11:13:11.608  INFO 51092 --- [           main] irpd.web.rest.AccountResourceIntTest     : No active profile set, falling back to default profiles: default
2017-12-01 11:13:20.716  INFO 51092 --- [           main] irpd.config.MetricsConfiguration         : Initializing Metrics Log reporting
2017-12-01 11:13:27.035 ERROR 51092 --- [           main] liquibase 

非常感谢任何帮助。

【问题讨论】:

  • JHipster 不是一个框架,只是一个代码生成器。

标签: svg blob h2 jhipster liquibase


【解决方案1】:

JHipster 不使用 Liquibase 为您的实体插入数据,它只为它自己的与用户管理相关的实体:用户、权限等......

因此,此错误是由于您更改从 JHipster 生成的 Liquibase 迁移 20171023230151_added_entity_Pattern.xml 加载数据而导致的,问题很可能在于您在 patterns.csv 中编码数据的方式。

您应该创建自己的迁移来加载您的数据,这样您可以让 JHipster 管理此文件并将您的数据编码为 CSV 中的十六进制。请注意,在 SQL 中对二进制数据进行编码没有标准方法,所以如果你让它在 H2 中工作,并不意味着它可以在你的生产数据库中工作。见Inline BLOB / BINARY data types in SQL / JDBC

或者,如果您在 XML 中仅使用 SVG,您可以使用 CLOB(长文本)而不是 BLOB,因为 Jhipster 提供了此选项。

更简单的方法是在服务或 JUnit 测试中编写一些 java 代码,以使用 ClasspathResource 读取 SVG 文件并调用 PatternRepository 将它们保存在数据库中。

【讨论】:

  • 感谢您的评论。我不知道如何在 CSV 中将数据编码为十六进制。分别地,不可能将我的 SVG 保存为十六进制,对吧?所以我可能会尝试将 SVG 保存为 CLOB。但我仍然不明白为什么我会收到错误消息,告诉我字符串包含非十六进制字符?为什么是十六进制?
  • 在运行我的测试时是否可以以某种方式排除此列?当我运行任何 JUnit 测试时,它都会经历以下过程:irpd.web.rest.AccountResourceIntTest、irpd.config.MetricsConfiguration、liquibase...见上面的扩展编辑
  • 这是 H2(和其他数据库)的要求,不,您不能在测试中排除列。底线是:不要使用 CSV 加载二进制数据,它不适应。我编辑了我的答案。
  • 感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-22
  • 2019-06-30
  • 1970-01-01
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多