我有一个用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测试)。然而,当测试运行时,HSQLDB,@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
,因此它应该容纳任何字符串。
但我的插入仍然失败。我现在无意检查实际的内存数据库
有关申请的其他信息:
VARCHAR(max)
,所以我认为这不适用于我仍然,我需要存储大于255个字符的数据
有关如何修复的任何想法?在我的单元测试中,我仍然可以注释掉其中一个实体,但这只是一种解决方法。