私はRequest
、RequestSet
(同時に1人のユーザーによって提出された個々の要求の集まり)と要求Status
のドメインクラスを持っています。私は、リクエストのステータスが個々のリクエストの状態から決定されるようにリクエストのステータスを集計したいと思います。Grailsの派生プロパティを使用してドメインオブジェクトを取得できますか?
これらのドメインクラスの関連部分は次のようになります。
class RequestSet {
Long id
static hasMany = [requests: Request]
}
class Request {
Long id
Status status
}
class Status {
Long id
String status
}
が、私はそうのようRequestSet
クラスに派生status
プロパティを追加してみました:
class RequestSet {
Long id
Status status
static hasMany = [requests: Request]
static transients = ['status']
static mapping = {
status formula: '(SELECT MIN(status_id) FROM (SELECT status_id FROM request rq WHERE rq.request_set_id = id))'
}
}
私は私のアプリを実行し、検査ただし、requestSetオブジェクトのプロパティーは、すべてnullです。
派生プロパティを使用しても可能なことを達成しようとしていますか?私はゲッターで一時的なプロパティを解決することができますが、動的なファインダを使用してバブルアップ状態に基づいてrequestSetを取得できるようにしたいと考えています。私が見たすべての例は、その式の結果をそのまま使用しています。 Grailsに返された値をStatus
クラスのIDとして解釈させることができるかどうかを知りたいと思います。
EDIT、2016年12月7日:派生語としてstatus
プロパティを一時的にマークしました。そうすることなく、私はHibernateからClassCastException
を取得します。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'transactionManager_companion' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_companion': Cannot resolve reference to bean 'sessionFactory_companion' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_companion': Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.mapping.Formula cannot be cast to org.hibernate.mapping.Column
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
私は式が、それは一時的なものとしてマークされていますので、私は、このプロパティを使用して、動的ファインダーを使用することはできません働く場合でも疑いがあります。私は状態のIDを計算するために数式を使用することで解決しますが、私はまだそれに問題があります。
class RequestSet {
Long id
Long statusId
static hasMany = [requests: Request]
static mapping = {
statusId formula: '(SELECT MIN(status_id) FROM (SELECT rq.status_id FROM request rq WHERE rq.request_set_id = id))'
}
}
要求セットをフェッチするときの式で生成されたSQLが
(SELECT MIN(this_.status_id) FROM (SELECT rq.status_id FROM request rq WHERE rq.request_set_id = this_.id)) as formula3_0_ from request_set
であると私はSQLSyntaxErrorException
取得しています:ORA-00904: "THIS_"."STATUS_ID": invalid identifier
を
今私のドメインクラスは次のようになります。私は式を書き直して 'this_'を書き換えることができます。 status_idの前に追加されていませんか?