- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我在尝试将对象数组写入数据库时遇到了 Hibernate 问题。重要的是我有一个从 Web 服务查询构建的对象。这个对象“响应”最多可以包含十个“未付费项目”,当我尝试保留这些项目时,就会出现问题。
实体:
@Entity
@Table(name="TABLE_NAME")
public class AccountDetailsRROutput implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String payeename;
private String typeunpd;
private BigDecimal unpdamt;
@Column(name="TRANSACTION_ID")
private long transactionId;
public AccountDetailsRROutput() {
super();
}
// plus all get/sets
}
//================================================================
// Populate the output for the repeating rows table
// which can contain a maximum of 10 unpaid items
//===============================================================
AccountDetailsRROutput outputRRTable[] = new AccountDetailsRROutput[response.getLineItems().length];
LOGGER.debug(METHOD_NAME, "Loop through the line items");
for (int i = 0; i < response.getLineItems().length; i++) {
//================================================================
// Ensure that we have an item so we don't write an empty row
//================================================================
if (response.getLineItems()[i].getTypeunpd() == null || response.getLineItems()[i].getTypeunpd() == "") {
LOGGER.debug(METHOD_NAME, "No unpaid item entry so break out of the the loop");
break;
}
else {
LOGGER.debug(METHOD_NAME, "We've got an unpaid item so add the details to the DB");
outputRRTable[i] = new AccountDetailsRROutput();
outputRRTable[i].setTransactionId(iTransactionID);
outputRRTable[i].setTypeunpd(response.getLineItems()[i].getTypeunpd());
outputRRTable[i].setPayeename(response.getLineItems()[i].getPayeeName());
outputRRTable[i].setUnpdAmt(response.getLineItems()[i].getUnpdAmt());
//================================================================
// Persist the output list DB object
//================================================================
LOGGER.debug(METHOD_NAME, "Persist repeating rows table DB object for line item: " + (i+1));
em_i.persist(outputRRTable[i]);
}
}
LOGGER.debug(METHOD_NAME, "Finished persisting repeating rows table DB object");
em_i.flush();
当我尝试此操作时,出现以下错误:
org.hibernate.NonUniqueObjectException:具有相同标识符值的不同对象已与 session 关联:
我可以通过将 emi.persist 更改为 emi.merge 来解决这个问题,但它只是将一个元素写入数据库。该表中可以有重复记录,不存在pk。
最佳答案
您可能有不止一件商品具有相同的收款人姓名
。尝试定义另一个 id(例如由 payeename
和 transactionID
组成的 id)。
关于java - 持久化对象时出现 NonUniqueObjectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13378268/
大家好,我在尝试将对象数组写入数据库时遇到了 Hibernate 问题。重要的是我有一个从 Web 服务查询构建的对象。这个对象“响应”最多可以包含十个“未付费项目”,当我尝试保留这些项目时,就会
当我使用 JPA 持久保存对象时,出现 NonUniqueObjectException。 我持久化的对象有其他对象,并且在某些情况下这些对象具有相同的 id。 可以对已保存在数据库中的对象进行合并,
我在 Java Hibernate 中使用 SINGLE_TABLE 继承策略,这里是设置: Class A @Cascade(CascadeType.DELETE_ORPHAN, CascadeT
我们使用 DTO 模式将我们的域对象从服务层编码到我们的存储库,然后通过 NHibernate 向下编码到数据库。 我遇到了一个问题,我从存储库中提取了一个 DTO(例如 CustomerDTO),然
我正在编写一个博客引擎作为学习练习。我知道那里有很多博客引擎,但请耐心等待... 我有一个 BlogPost 实体,它有一个属性标签,它是一个与之关联的标签的 IList。 BlogPost.SetT
我有这个简单的情况: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(Cascad
我有一个包含子实体集合的父实体,几乎每次我访问该父实体时都需要从 web 服务更新这些子实体。我想我可以只对集合执行 Clear(),然后添加我从 Web 服务收到的实体列表。当我收到的实体没有与我刚
我收到这个错误: a different object with the same identifier value was already associated with the session:
我有一个非常简单的方法: public D saveDocument(D document) { final Session currentSession = getCurrentSessio
当我想从数据库中删除对象时出现错误。错误是: org.hibernate.NonUniqueObjectException: a different object with the same iden
我有一个包含 2 个主键的表(所以它们的组合应该是唯一的)。架构是这样的: TABLE="INVOICE_LOGS" INVOICE_NUMBER PK non-null INVOICE_TYPE
我在将多个对象保存到数据库时遇到问题。我得到 org.hibernate.NonUniqueObjectException: 具有相同标识符值的不同对象已与 session 关联我的代码:配置cfg
我有一个实体,其中包含另外两个具有@ManyToOne 关系的实体。 @Entity public class A extends Serializable{ @Id @Generat
当我尝试将给定图像两次添加到同一个目标城市时,出现以下异常: NonUniqueObjectException: a different object with the same identifier
从 grails webapp 添加记录时,我收到 NonUniqueObjectException。发生这种情况是因为 webapp 的用户能够添加记录,并且他们填写的字段之一是域对象/db 表的
尝试从 session 中删除地址对象时,出现此异常org.hibernate.NonUniqueObjectException:具有相同标识符值的不同对象已与 session 关联。 以下是调用源码
我使用 MySQL、Hibernate、JPA 和 Spring,我的问题是我无法一对一关联更新子表;我正在使用外国策略。 当我使用 saveOrUpdate 并调用第一次方法时,我可以将实体保存到数
我有 3 个不同的实体类,即 Pashmina、Description、Image、PashminaColour。这里,Pashmina 与描述、图像和 PashminaColour 具有一对多关系。
在我的模型中有3个实体(实际上超过3个,但实际上是3个实体处于这种情况) Candidate Vacancy Event 它们都具有多对多的关系(候选人可以有可能的空缺和许多 Activity ,空缺
在我的模型中有3个实体(实际上超过3个,但实际上是3个实体处于这种情况) 候选人 职位空缺 Activity 它们都具有多对多的关系(候选人可以有可能的空缺和许多 Activity ,空缺......
我是一名优秀的程序员,十分优秀!