简体   繁体   中英

Grails domain constraints mapping

I'm working on grails 2.4.5 On the domain class, I define:

String CARD_NO
String USER_ID
String PASSWORD

and the constraints:

CARD_NO(nullable: false, blank: false, maxSize: 24, unique: 'USER_ID')
USER_ID(nullable: false, blank: false, maxSize: 32)
PASSWORD(nullable: false, blank: false, maxSize: 64)

However If I got script like:

"CARD_NO"                  VARCHAR2(24 BYTE) NOT NULL ENABLE,
"USER_ID"                  VARCHAR2(32 BYTE),
"PASSWORD"                 VARCHAR2(64 BYTE),
CONSTRAINT "CARD_USER_PK" PRIMARY KEY ("ISSUER_ID", "CARD_NO") ,
CONSTRAINT "USER_ID_UNIQUE" UNIQUE ("USER_ID") ,

Is this any possible way to mapping constraints with given script? Any solution will be appreciated. Thanks.

You only need to write what you need in domain class, for example, if you have 5 field in your actual table in database but you only need 3 field in your program, you can just write that 3 field in your domain class. That case also work with the relation, you can just write the relation that you need only.

But there is an exception if you want to filter or validate(all elemen) an domain class.

You can use grails db reverse engineer plugin to get domain class from existing table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM