问题描述
我试图在遗留数据库(仍然有一个传统PHP客户端)上实现hibernate,并且遇到了一些问题,因为编写原始应用程序的人不知道他们在做什么。
I am trying to implement hibernate on a legacy database (that still has a legacy PHP client), and am running into some problems because the people who wrote the original app had no idea what they were doing.
数据库设置为不能为空,所以如果没有记录,它们会将外键默认为0。另外,他们在表上没有适当的外键,所以有少数无效的ID。我没有选择更改模式或将适当的列置空。
The database is set up so that none of the columns are nullable, so they default foreign keys to 0 if there is no record for them. Additionally, they don't have proper foreign keys on the tables so there are a few with invalid IDs. I do not have an option to change the schema or null the appropriate columns.
这是我从hibernate获得的错误:
This is the error I get from hibernate:
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.tv.platform.domain.Program#0]
我想要的是一种优雅的方式来处理这个问题,如果行无效或者不行不存在,但我没有任何运气发现如何处理这个文件。
What I would like is a graceful way to deal with this muck, where the field will just null if the row is invalid or doesn't exist, but I am not having any luck finding how to handle this in the documenation.
任何提示?
推荐答案
注释:
@NotFound(action = NotFoundAction.IGNORE)
The annotation: @NotFound( action = NotFoundAction.IGNORE )
对于。我通过这里找到它:
Does exactly what I was looking for. I found it through here:
这篇关于处理遗留数据库时,Hibernate在缺失行上扼流圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!