私は多くの投稿やドキュメントを読みましたが、何かが欠けているに違いありません。
私のアプリケーション (以下のモデル) では、結合テーブル JOBORDERCATEGORIES にカテゴリ ID があり、CATEGORY テーブルに対応する行がないため、制御不能と思われるデータの問題が発生しています。JobOrder の getJobCategories() を介してカテゴリ データにアクセスしています。カテゴリ テーブルに参照行がない場合、次のエラーが発生します。
2012-03-07 08:02:10,223 [quartzScheduler_Worker-1] ERROR listeners.SessionBinderJobListener - Cannot flush Hibernate Sesssion, error will be ignored
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.matrixres.domain.Category#416191]
私のコードは停止しています。
ignoreNotFound を使用してみましたが、上記のエラーを回避するのに役立ちません。
この問題の解決策に関する投稿を見逃した場合は、リンクしてください。それ以外の場合は、前進する方法についての考えを歓迎します。適切なカテゴリ リストを取得するという目標を達成するためには、もっと直接的なルートをたどらなければならないかもしれませんが、次に何をすべきかを知るには、フレームワークに精通していません。注意として、これらのテーブルのいずれにも書き込むことはできません。
ありがとう、金持ち
私のモデルの簡略化されたバージョン:
ジョブ オーダー オブジェクト:
class JobOrder {
def getJobCategories() {
def cats = []
try {
def jocategories = this.categories
if(!jocategories.isEmpty() && jocategories!=null){
println "we got categories for ${this.id}"
jocategories.each { cat ->
if(cat?.parentCategoryID == 0){
if(cat.occupation != null){
cats << cat.occupation
} else {
cats << cat.name
}
}
}
}
} catch(e) {
cats << "Other Area(s)"
}
cats
}
static mapping = {
table 'dbo.JOBORDER'
version false
id generator: 'identity', column: 'JOBORDERID'
/*
* several other mapped columns deleted here
*/
categories joinTable:[name:'jobOrderCategories', column: 'categoryId', key:'jobOrderID']
}
/*
* several properties deleted here
*/
static hasMany = [categories: Category] //several other hasMany associations exist
}
カテゴリ オブジェクト:
class Category {
static mapping = {
table 'CATEGORY'
version false
id generator: 'identity', column: 'categoryID'
occupation column: 'OCCUPATION'
name column: 'NAME'
parentCategoryID column: 'PARENTCATEGORYID'
/*
* several other mapped columns deleted here
*/
jobOrders joinTable:[name:'jobOrderCategories', column: 'jobOrderID', key:'categoryId']
}
String name
String occupation
int parentCategoryID
/*
* several properties deleted here
*/
static belongsTo = [JobOrder]
static hasMany = [jobOrders:JobOrder]
}
結合テーブル:
class JobOrderCategories {
static mapping = {
table 'JOBORDERCATEGORIES'
version false
isDeleted column: 'ISDELETED'
jobOrderID column: 'JOBORDERID'
categoryId column: 'CATEGORYID'
}
Boolean isDeleted
Integer jobOrderID
Integer categoryId
}