我目前正在开发一个场景,我有一个集中式数据库和两个不同地区的扩展数据库,即美国和英国。 Site和TestSubjectPublic位于集中式数据库中,而Document位于扩展数据库中。 TestSubjectPublic与文档有hasOne和BelongsTo关系。 我已经覆盖了getter和setter,但出于某种原因,每当我获取数据时,它都会将testSubjectResult发送为null。以下是域类
class Site {
String name
String notes
String email
String phone
String creditCardNumber
String chargeForTest
Boolean isEnabled = true
Byte deleted = 0
Byte taxExempt =1
static hasMany = [testSubjects: TestSubjectPublic]
Float discountAmount
SiteType type
AccountStatus accountStatus=Site.AccountStatus.ACTIVE
Date accountClosingDate
Long fedexTrackingNumber
Date dateFedexNumberAdded
String signUpToken
Integer monthOfMoreThanFifteenTests
Date dateSignUpInviteSent
String vatNumber
String website
static constraints = {
name(unique: true, nullable: false, blank: false)
email(email: true, nullable: false, blank: false)
phone(nullable: true)
notes(maxSize: 5000, nullable: true)
creditCardNumber(nullable: true)
chargeForTest(nullable: true)
accountStatus(inList: AccountStatus.values().toList())
accountClosingDate(nullable: true)
type(inList: SiteType.values().toList())
fedexTrackingNumber(nullable: true)
dateFedexNumberAdded(nullable: true)
signUpToken(nullable: true)
monthOfMoreThanFifteenTests(nullable: true)
dateSignUpInviteSent(nullable: true)
vatNumber(nullable: true)
taxExempt(nullable: false)
website(nullable: true)
discountAmount(nullable: true)
}
enum AccountStatus {
ACTIVE, INACTIVE
}
enum SiteType {
SCHOOL, GENERAL_PRACTITIONER, OTHER
}
static mapping = {
}
}
TestSubjectPublic.groovy
import groovy.transform.ToString
@ToString(includeNames=true)
class TestSubjectPublic {
String emailId
String telephoneNumber
//Specific name/id given in site
String sitePatientId
String dialingCode
//Reference number in QbTest
String qbTestPatientId
TestSubjectStatus status
Byte deleted = 0
static belongsTo = [site: Site]
static constraints = {
site(nullable: true)
sitePatientId(nullable: true)
qbTestPatientId(nullable: true)
dialingCode(nullable: true)
status(inList: TestSubjectStatus.values().toList())
emailId(nullable: true)
telephoneNumber(nullable: true)
}
enum TestSubjectStatus {
NOT_COMPLETED, COMPLETED
}
static mapping = {
}
}
document.groovy的
class Document {
Long testSubjectPublicId
private TestSubjectPublic testSubjectPublic
String filename
byte[] filedata
enum DocType {
RAW,PG,JSON
}
DocType type
Date uploadDate = new Date()
TestSubjectPublic getTestSubjectPublic() {
if (!testSubjectPublic && testSubjectPublicId) {
testSubjectPublic = TestSubjectPublic.get(testSubjectPublicId)
}
testSubjectPublic
}
void setTestSubjectPublic(TestSubjectPublic tsp) {
testSubjectPublicId = tsp.id
}
static transients = ['testSubjectPublic']
static constraints = {
filename(blank:false,nullable:false)
filedata(blank: true, nullable:true, maxSize:1073741824)
testSubjectPublic(nullable: true)
}
static mapping = {
datasources(['virginia','ireland'])
table name: "document"
}
}
当我尝试列出文档时
listItems = Document.virginia.list(params)
testSubjectPublic对象为空
这是我的datasource.groovy,目前我在Dev environemnt
development {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/abc838?zeroDateTimeBehavior=convertToNull"
username = "root"
password = "root"
}
dataSource_virginia {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/abc8382?zeroDateTimeBehavior=convertToNull"
username = "root"
password = "root"
}
dataSource_ireland {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/abc838ireland?zeroDateTimeBehavior=convertToNull"
username = "root"
password = "root"
}
}