带有遗留数据库的圣杯.外键作为主键的一部分



我遇到了使用遗留数据库的问题。我有两个与关系相关的表:一个 – 到 – 多:表订阅者:

create table SUBSCRIBERS
(
  SUBSCRIBERCODE VARCHAR2(100) not null,
  SUBSCRIBERNAME VARCHAR2(100),
  ACTIVE         CHAR(1) default 'Y' not null
)
alter table SUBSCRIBERS
  add constraint SUBSCRIBERS_PK primary key (SUBSCRIBERCODE);

表订阅者联系人:

create table SUBSCRIBERSCONTACTS
(
  SUBSCRIBERCODE VARCHAR2(100) not null,
  CONTACTTYPE    VARCHAR2(100) not null,
  ORDER_ID       NUMBER not null,
  CONTACTVALUE   VARCHAR2(100) not null,
  ACTIVE         CHAR(1) default 'Y' not null
)
alter table SUBSCRIBERSCONTACTS
  add constraint SUBSCRIBERSCONTAC1 primary key (SUBSCRIBERCODE, CONTACTTYPE, ORDER_ID);
alter table SUBSCRIBERSCONTACTS
  add constraint SUBSCRIBER_SUBS_FK foreign key (SUBSCRIBERCODE)
  references SUBSCRIBERS (SUBSCRIBERCODE);

表 SUBSCRIBECONTACTS 具有复合主键 – (SUBSCRIBERCODE, CONTACTTYPE, ORDER_ID)。此外,它还具有对订阅者(订阅者代码)的外键引用。订阅者代码是订阅者联系人主键的一部分。

我创建了两个 GORM 域类:

package tmsconf
class Subscribers {
String id
String subscribercode
String subscribername
String active
static hasMany = [subscriberscontacts:Subscriberscontacts]
static mapping = {
version false
id generator: 'assigned', name: 'subscribercode'
}

static constraints = {
subscribercode(size:1..100, blank: false)
subscribername(size:0..100, nullable: true)
active(size:1..1, blank: false)
}
public void setSubscribercode( String subscribercode ){
this.subscribercode = subscribercode
this.id = subscribercode
}
String toString() {
subscribercode
}
}
package tmsconf
class Subscriberscontacts  implements Serializable{
String id
Subscribers subscribers
String contacttype
Long order_id
String contactvalue
String active
static mapping = {
version false
id composite: ["subscribercode", "contacttype","order_id"], generator: "assigned"
subscribers name : 'subscribercode', column : 'subscribercode', insertable: false, updateable: false
}
public String getSubscribercode()
{
    subscribers
}

static constraints = {
contacttype(size:1..100, blank: false)
contactvalue(size:1..100, blank: false)
active(size:1..1, blank: false)
}
public void setSubscribercode( String subscribercode ){
this.subscribercode = subscribercode
this.id = subscribercode
}

String toString() {
subscribercode
}

}

我生成了所有必需的:圣杯生成 - 全部 *。

然后我尝试运行新的 grails 应用程序并出现异常:

Caused by PropertyNotFoundException: Could not find a getter for subscribercode in class tmsconf.Subscriberscontacts
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    166 | run       in java.util.concurrent.FutureTask
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

我不想将订阅者代码属性添加到订阅者联系人域类,因为如果我这样做,我将在创建表单上获得订阅者代码编辑字段。

添加它,只需隐藏脚手架:

class Subscriberscontacts {
  String subscribercode
  ...
  static constraints = {
    subscribercode display: false // or editable: false
  }
}

相关内容

  • 没有找到相关文章

最新更新