- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 hibernate 做一个简单的查询。没有连接。我要做的就是从表中检索最大 id。这项服务几个月来一直运行良好,但突然间,在过去的两周内,我收到了可怕的 No row with the given identifier exists 错误。即使此表包含数百万行。这怎么会发生?
这是执行查找的服务:
try {
session = HibernateUtils.beginTransaction("mydatabase");
criteria = session.createCriteria(MyClass.class);
criteria.setMaxResults(1);
Order order = Order.desc("id");
criteria.addOrder(order);
myclass = (MyClass) criteria.uniqueResult();
} catch (HibernateException e_) {
e_.printStackTrace();
String msg = "Problem getting maximum id from myclass table "
+ e_.getCause();
LOG.error(msg);
throw new DataBaseAccessException(msg);
}finally {
try {
HibernateUtils.closeSessions();
} catch (Exception e_) {
}
}
最佳答案
即使您在没有连接的情况下对单个表进行查询,查看查询中涉及的基础模型也很重要。如果该模型有一个连接列并且关联的外键不存在于连接表中, hibernate 将失败。
在这种情况下,底层模型如下:有一个连接列 cid 映射到另一个表 code_table。但是在icdtable中查询的值在code_table中没有对应的条目。即使查询仅在 icdtable 上进行,但底层模型与另一个表连接的事实要求跨表的数据完整性,而不仅仅是在执行查询的表中。
@Entity
@Table (name="icdtable", catalog="emscribedx")
public class Icdtable {
private Long _icdid;
private Long _cid;
private String _icdcode; //TODO: add this to hibernate mappings ('PN' or 'NN')
private String _status;
private String _create_date;
private String _kstatus;
private int _enterorder;
private String _poa;
private String _ppoa;
private String _userid;
private Code_table _code_table1;
private List<Proceduredetail> _proceduredetails;
@Id
@Column (name = "icdid")
public Long getIcdid() {
return _icdid;
}
public void setIcdid(Long icdid_) {
_icdid = icdid_;
}
@Column (name = "cid")
public Long getCid() {
return _cid;
}
public void setCid(Long cid_) {
_cid = cid_;
}
@Column (name = "icdcode")
public String getIcdcode() {
return _icdcode;
}
public void setIcdcode(String icdcode_) {
_icdcode = icdcode_;
}
@Column (name = "status")
public String getStatus() {
return _status;
}
public void setStatus(String status_) {
_status = status_;
}
@Column (name = "create_date")
public String getCreate_date() {
return _create_date;
}
public void setCreate_date(String createDate_) {
_create_date = createDate_;
}
@Column (name = "kstatus")
public String getKstatus() {
return _kstatus;
}
public void setKstatus(String kstatus_) {
_kstatus = kstatus_;
}
@Column (name = "enterorder")
public int getEnterorder() {
return _enterorder;
}
public void setEnterorder(int enterorder_) {
_enterorder = enterorder_;
}
@Column (name = "poa")
public String getPoa() {
return _poa;
}
public void setPoa(String poa_) {
_poa = poa_;
}
@Column (name = "ppoa")
public String getPpoa() {
return _ppoa;
}
public void setPpoa(String ppoa_) {
_ppoa = ppoa_;
}
@Column (name = "userid")
public String getUserid() {
return _userid;
}
public void setUserid(String userid_) {
_userid = userid_;
}
@ManyToOne
@JoinColumn(name = "cid", insertable=false, updatable=false)
public Code_table getCode_table() {
return _code_table1;
}
public void setCode_table(Code_table code_table_) {
_code_table1 = code_table_;
}
@OneToMany (mappedBy = "icdtable", targetEntity = Proceduredetail.class, cascade = CascadeType.ALL)
public List<Proceduredetail> getProceduredetails() {
return _proceduredetails;
}
public void setProceduredetails(List<Proceduredetail> proceduredetails_) {
_proceduredetails = proceduredetails_;
}
关于java - 组织.hibernate.ObjectNotFoundException : No row with the given identifier exists: Single table query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10002228/
我想使用结构 DataResponse 作为 JSON() 的参数来响应用户。通过初始化 DataResponse 的实例,我得到了错误消息,给出了太多的参数,但给出了所有必要的参数。 type Da
我正在尝试将 google-one-tap 与本地主机上的 django 项目集成。所以我在 Client ID for Web 的 Authorized JavaScript origins 中添加
考虑一个类A,我如何编写一个具有与相同行为的模板 A& pretty(A& x) { /* make x pretty */ return x; } A pretty(A&& x) {
我正在使用 Hibernate envers 3.6.3.Final。我可以审核表,我可以看到 _audit 表中填充了 revision_number、revision_type 和实体数据。 我正
问题详细描述如下: 给定两个单词(beginWord 和 endWord)和字典的单词列表,找出是否存在从 beginWord 到 endWord 的转换序列,这样: 一次只能更改一个字母 每个转换后
我正在尝试解析任何选定的 mysql 表的单行的所有列字段和数据。 这背后的原因是为任何给定的单行创建一个类似“通用”的表解析器。 例如,我有这个表“tbl1”: +----+------------
我有一个列表,它可能包含也可能不包含重复的元素。给定另一个列表/元素集,我需要该列表中存在的所有唯一元素的列表。 Input: input_list = ['android', 'ios', 'and
需要编写一个算法来查找给定字符串在给定索引处的 Anagram,并按字典顺序排序。例如: Consider a String: ABC then all anagrams are in sorted
给定学生和铅笔的数量,假设学生有 154 名,铅笔有 93 名,如何用 Python 编写代码来获得比率。 输出:x:y 或者说给定两个数字的百分比并找出比率。 输出:x:y 最佳答案 import
给定学生和铅笔的数量,假设学生有 154 名,铅笔有 93 名,如何用 Python 编写代码来获得比率。 输出:x:y 或者说给定两个数字的百分比并找出比率。 输出:x:y 最佳答案 import
作为一名端到端自动化测试人员,我一直认为 Given、When、Then 语句(在使用 Cucumber 时合并到 Gherkin 语言中)应该只按 1.Given、2.When、3 的顺序出现.然后
我正在尝试以动态方式传递参数。我想使用 Perl 函数 given(){},但由于某种原因,我不能在其他任何东西中使用它。这就是我所拥有的。 print(given ($parity) { wh
我想在 cucumber 中测试以下功能。但是,我只想处理输入文件一次(以下功能中的@Given)。但是,它似乎每次都执行@Given 步骤。是否可以在以下功能中仅执行一次此@Given? @file
我想知道是否可以使用 given 参数来自 pytest 的 parametrize 函数。 示例: import pytest from hypothesis import given from h
在deep learning tutorials ,所有训练数据都存储在一个shared数组中,只有该数组的索引被传递给训练函数以切出一个小批量。我知道这允许将数据保留在 GPU 内存中,而不是将小块
我正在尝试运行以下代码: foreach my $k (keys %rec) { #switch for watchlist figures given ($k) { #line 93
我正在尝试在完全支持的情况下使用 GWT 规范,但是它的示例 official documentation有点简单。 在 SO 中搜索我发现了这个问题: Specs2 - How to define
我使用hypothesis 已经有一段时间了。我想知道如何重用 @given parts。 我有一些大约 20 行,我将整个 @given 部分复制到几个测试用例之上。 一个简单的测试例子 @give
我在运行 rspec 文件时不断收到错误: Failures:
让我们调用一个函数 function doSomethingAndInvokeCallback(callback){ // do something callback(); } 我可以
我是一名优秀的程序员,十分优秀!