向该服务使用的域对象之一添加新关联后,我在 Spock 测试中收到此错误。我没有发现任何引用此异常的 Grails 相关或 GORM 相关问题。 我能找到的所有东西都是直接使用 Hibernate 并且已经有 5 年以上的历史了。
An association from the table classification refers to an unmapped class: com.myCompany.Classifier
这是测试课
package com.myCompany
import grails.test.hibernate.HibernateSpec
import grails.testing.gorm.DataTest
import grails.testing.services.ServiceUnitTest
class StatusQueueServiceSpec extends HibernateSpec implements ServiceUnitTest<StatusQueueService>, DataTest {
def setup() {
...
}
void "test handleStatusChange"() {
...
}
}
这是
Classifier
域对象
package com.myCompany
import grails.compiler.GrailsCompileStatic
import grails.plugins.orm.auditable.Auditable
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import static com.myCompany.ClassifierType.SAGEMAKER
@GrailsCompileStatic
@EqualsAndHashCode(includes = 'name')
@ToString(includes = 'name', includeNames = true, includePackage = false)
class Classifier implements DomainClass, Auditable {
String name
ClassifierType classifierType = SAGEMAKER
Date dateCreated
Date lastUpdated
static constraints = {
name nullable: false, blank: false, maxSize: 256, unique: true
classifierType nullable: false, blank: false
}
}
这是
Classification
域对象
package com.myCompany
import groovy.transform.ToString
import org.grails.datastore.mapping.core.connections.ConnectionSource
@ToString(includeNames = true, includePackage = false, includes = ['photo', 'classifier', 'score'])
class Classification implements DomainClass {
static String GOOD = 'GOOD'
static String BAD = 'BAD'
static String MAYBE = 'MAYBE'
static String UNCLASSIFIED = 'UNCLASSIFIED'
float score
PhotoRequirement photoRequirement
Classifier classifier
Photo photo
static belongsTo = [PhotoRequirement]
static constraints = {
score nullable: false
photoRequirement nullable: true, unique: 'photo'
classifier nullable: true
photo nullable: false
}
static mapping = {
datasources([ConnectionSource.DEFAULT, 'readReplica'])
}
}
问题是我延长了
HibernateSpec
而不是Specification
。
import spock.lang.Specification
class StatusQueueServiceSpec extends Specification implements ServiceUnitTest<StatusQueueService>, DataTest {