我遇到过使用旧数据库的问题。 我有两个表关联:一对多: 表订阅者:
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
我不想将Subscription属性添加到Subscriberscontacts域类,因为如果我这样做,我将在Create form上获得subscribercode edit字段。
答案 0 :(得分:0)
添加它,只需隐藏脚手架:
class Subscriberscontacts {
String subscribercode
...
static constraints = {
subscribercode display: false // or editable: false
}
}