0

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

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);

表 SUBSCRIBERSCONTACTS 具有复合主键 - (SUBSCRIBERCODE, CONTACTTYPE, ORDER_ID)。它还具有对 SUBSCRIBERS (SUBSCRIBERCODE) 的外键引用。SUBSCRIBERCODE 是 SUBSCRIBERSCONTACTS 主键的一部分。

我创建了两个 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 generate-all *.

然后我尝试运行新的 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

我不想将subscribercode 属性添加到Subscriberscontacts 域类,因为如果这样做,我将在Create 表单上获得subscribercode 编辑字段。

4

1 回答 1

0

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

class Subscriberscontacts {
  String subscribercode
  ...
  static constraints = {
    subscribercode display: false // or editable: false
  }
}
于 2012-10-15T11:26:55.197 回答