仅在HSQLDB上发生意外的数据截断

时间:2016-04-29 11:29:07

标签: java hibernate hsqldb

我有一个用JPA注释定义的实体(这里只显示了几个感兴趣的领域)

@Entity
public class Rule implements Serializable, Cloneable
{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO,
            generator = "SEQ_STORE")
    @Column(name = "RULE_ID",
            nullable = false)
    private final Long id = null;

    @Column(name = "CODE",
            length = 25,
            nullable = false)
    private String code;

    @Column(name = "DESCRIPTION",
            length = 250,
            nullable = true)
    private String description;


    @Column(name = "VALIDATION_FIELDS",
            length = 250,
            nullable = true)
    private String validationFields;

    @ExportField("EXPRESSION")
    @Lob
    @Column(name = "EXPRESSION",
            nullable = true)
    private String expression;

    @Lob
    @Column(name = "ACTION",
            nullable = true)
    private String action;


    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "PARENT_ID",
            nullable = true,
            foreignKey = @ForeignKey(name = "FK_XTB_RULE_2_PARENT") )
    private Rule parent;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "RULESET_ID",
            nullable = false,
            foreignKey = @ForeignKey(name = "FK_XTB_RULE_2_RULESET") )
    private RuleSet ruleSet;

}

@Entity
public class RuleSet implements Serializable, Cloneable
{

    private static final long serialVersionUID = 7982682149517239983L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO,
            generator = "SEQ_STORE")
    @ExportField("RULESET_ID")
    @Column(name = "RULESET_ID",
            nullable = false)
    private final Long id = null;



    @JsonIgnore
    @OneToMany(mappedBy = "ruleSet",
            fetch = FetchType.EAGER,
            cascade = CascadeType.ALL)
    @OrderBy("position")
    private List<Rule> rules = new LinkedList<Rule>();
}

然后我有一个生成这些Rule的方法(参见反向引用)并将所有规则放入{{1}中包含的List中实体。

自动生成的DDL使列适用于大Ruleset,因为列expression已注释

在Mysql和Oracle上我可以成功运行填充规则表的代码(我每次都运行从头开始创建DB的Bamboo测试)。然而,当测试运行时,HS​​QLDB,@Lob对象的Hibernate&lt; insert失败

Ruleset

在我的代码中有一个长353个字符的表达式,我几乎找到了#34;有罪&#34;对象

但问题是,即使使用HSQLDB,也会生成以下DDL

2016-04-29 13:09:26,946 WARN  [localhost-startStop-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - logExceptions - SQL Error: 3401, SQLState: 22001
2016-04-29 13:09:26,949 ERROR [localhost-startStop-1] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - logExceptions - data exception: string data, right truncation;  table: XTB_RULES column: EXPRESSION
2016-04-29 13:09:39,965 ERROR [localhost-startStop-1] it.phoenix.web.data.managers.spring.ModuleManagerImpl - init       - could not execute statement
org.hibernate.exception.DataException: could not execute statement
...
Caused by: org.hsqldb.HsqlException: data exception: string data, right truncation;  table: XTB_RULES column: EXPRESSION
...
Caused by: org.hsqldb.HsqlException: data exception: string data, right truncation

create table XTB_RULE_FUNCTIONS (RULE_FUNCTION_ID bigint identity not null, DESCRIPTION varchar(250), ENABLED bit not null, EXPRESSION varchar(MAX) not null, NAME varchar(50) not null, OBJECT_TYPE varchar(20) not null, POSITION bigint not null, primary key (RULE_FUNCTION_ID)); 应该是EXPRESSION,因此它应该容纳任何字符串。

但我的插入仍然失败。我现在无意检查实际的内存数据库

有关申请的其他信息:

  • 是否在Tomcat上运行Web应用程序
  • 我使用Bamboo CI在不同的数据库上运行测试,每个数据库都加载Spring上下文而不是在servlet容器中运行
  • 如果数据不存在,Spring初始化的一部分就是填充Ruleset表。由于Bamboo在每次运行时都会重新创建数据库(特别是内存中的数据库),所以我总是需要在一段代码中以编程方式填充规则,无法粘贴到此处
  • 我看过this,但我检查过DDL脚本声明VARCHAR(max),所以我认为这不适用于我
  • 一次又一次,相同的代码适用于其他数据库

仍然,我需要存储大于255个字符的数据

有关如何修复的任何想法?在我的单元测试中,我仍然可以注释掉其中一个实体,但这只是一种解决方法。

0 个答案:

没有答案