我在查询 Derby 数据库时遇到问题。我正在使用带有 JPA 的 Hibernate。问题(可能)与布尔列有关。每个查询都以错误结束:
org.hibernate.exception.SQLGrammarException:不支持“BOOLEAN”和“INTEGER”之间的比较。类型必须具有可比性。字符串类型也必须有匹配的排序规则。如果排序规则不匹配,一个可能的解决方案是将操作数强制转换为默认排序规则(例如 SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
您可以在下面找到示例代码和配置。简化示例以便于阅读。这是我的 JPA 实体:
@Entity
public abstract class Task implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
protected long id;
@Column
protected boolean deleted;
public long getId() {
return id;
}
public boolean isDeleted() {
return deleted;
}
public void setId(long id) {
this.id = id;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
@Override
public int hashCode() {
return id;
}
@Override
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (!this.getClass().equals(object.getClass())) {
return false;
}
EntityObject other = (EntityObject) object;
if (this.id != other.id) {
return false;
}
return true;
}
@Override
public String toString() {
return "EntityObject[ id=" + id + " ]";
}
}
我的 JPA 查询:
SELECT t FROM Task t WHERE deleted = false
我的 JPA 配置:
<persistence-unit name="PU1" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/myapp</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
</properties>
</persistence-unit>
怎么了?如何解决?感谢您的任何建议。