gpt4 book ai didi

oracle - 问题 ORA-00001 : unique constraint violated coming in INSERT/UPDATE

转载 作者:行者123 更新时间:2023-12-04 13:12:00 25 4
gpt4 key购买 nike

我试图通过应用程序在表中插入一些值并得到问题 ORA-00001:违反唯一约束。
我看到序列与表的最高 id 不同步,但即使修复了序列号,错误仍然存​​在。
我怎样才能更多地调试这个错误,oracle 日志是否给出了更多错误?我怎样才能看到oracle日志?
谢谢
普里扬克

更新:我们正在使用审计日志插件,在 User 的域类中,我们捕获保存事件并将条目记录到审计日志中

所以在 User 类中我们这样做:

class User {

//some attributes, constraints, mappings

def onSave = {
Graaudit aInstance = new Graaudit();
aInstance.eventType= "GRA User Create"
aInstance.eventDescription = "GRA User Created"
aInstance.objectid = username
aInstance.objecttype = 'GRAUSER'
aInstance.user_id = RequestContextHolder.currentRequestAttributes().session.username

aInstance.withTransaction{
aInstance.save()
}
}

}

当我们在 onSave 事件中没有上面的代码时,用户创建成功。我假设它与我们在一个实例上使用的 hibernate 事务有关,那是死亡或当前事务由于该保存而死亡。如果我们不使用交易,我们会得到一个异常 "org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"不知道如何解决这个问题..
谢谢

最佳答案

错误消息将包括违反的约束的名称(表上可能有多个唯一约束)。您可以使用该约束名称来标识在其上声明唯一约束的列

SELECT column_name, position
FROM all_cons_columns
WHERE constraint_name = <<name of constraint from the error message>>
AND owner = <<owner of the table>>
AND table_name = <<name of the table>>

一旦您知道哪些列受到影响,您就可以比较您尝试使用的数据 INSERTUPDATE对照表中已有的数据来确定违反约束的原因。

关于oracle - 问题 ORA-00001 : unique constraint violated coming in INSERT/UPDATE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9689412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com