在我的数据库中,我有一个表(默认值),当我从表生成一个实体时,我得到这两个类:
@Entity public class Defaults implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId protected DefaultsPK DefaultsPK; @Column(name = "ERTEK") private String ertek; getter/setter... } @Embeddable public class DefaultsPK implements Serializable { @Basic(optional = false) @Column(name = "VALUE_1") private String value1; @Basic(optional = false) @Column(name = "TYPE") private String type; @Basic(optional = false) @Column(name = "VALID_FROM") @Temporal(TemporalType.TIMESTAMP) private Date validFrom; @Basic(optional = false) @Column(name = "VALID_TO") @Temporal(TemporalType.TIMESTAMP) private Date validTo; getter/setter... }
这就是为什么因为主键包含值。
我想计算表中的所有行,所以我使用这段代码:
String sql = "SELECT COUNT(d) FROM Defaults d"; Query q = em.createQuery(sql); long count = (long)q.getSingleResult();
但是我收到了这个错误:
org.hibernate.exception.sqlGrammarException: could not execute query ... java.sql.sqlSyntaxErrorException: ORA-00907: The right expression is missing from the arithmetic expression
问题是什么?与其他实体的其他计数查询正在运行。
我正在使用hibernate。