问题ORA-00001:在INSERT / UPDATE中违反了唯一约束 [英] issue ORA-00001: unique constraint violated coming in INSERT/UPDATE
问题描述
我试图通过应用程序在表中插入一些值并获得问题ORA-00001:违反了唯一约束。
我看到序列与表的最高ID不同步,但即使在修复序号之后,错误仍然存在。
我怎样才能更多地调试这个错误,oracle日志会给出更多的错误?我怎样才能看到oracle日志?
感谢
Priyank
I am trying to insert some values in table throught the application and get issue ORA-00001: unique constraint violated. I see that sequences are out of sync with the highest id of the table, but even after fixing the sequence number the error still persists. How can I debug this error more, does oracle logs give more error? how can I see the oracle logs? Thanks Priyank
更新:我们使用审计日志记录插件,并且在用户的域类中,我们捕获保存事件并记录条目进入审计日志
update: we are using the audit logging plugin and in the domain class for User we catch the save event and log the entry into the audit log
所以在User类中,我们做:
So in User class we do:
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事件中没有上述代码时,用户被成功创建。 br>我假设它与我们在aInstance上使用的hibernate事务有关,那是因为那个保存而死亡或当前事务正在死亡。
如果我们不使用事务,我们得到一个异常 org.hibernate.HibernateException:没有Hibernate Session绑定到线程,并且配置不允许在这里创建非事务性的
不知道如何解决这个问题..
谢谢
When we dont have the above code in the onSave event the User is created successfully.
I am assuming its related to hibernate transaction which we are using on aInstance, thats dying or the current transaction is dying due to that save.
If we dont use the transaction we get an exception "org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"
Not sure how to fix this issue..
Thanks
推荐答案
错误消息将包含违反约束的名称(可能在表上有多个唯一约束)。您可以使用该约束名称来标识在
The error message will include the name of the constraint that was violated (there may be more than one unique constraint on a table). You can use that constraint name to identify the column(s) that the unique constraint is declared on
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>>
一旦您知道哪些列受到影响,您可以将您尝试的数据 INSERT
或 UPDATE
与表中已存在的数据进行比较,以确定违反约束的原因。
Once you know what column(s) are affected, you can compare the data you're trying to INSERT
or UPDATE
against the data already in the table to determine why the constraint is being violated.
这篇关于问题ORA-00001:在INSERT / UPDATE中违反了唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!