我正在尝试按其客户名称订购我的位置类,但由于某些原因无效。这是查询出错的部分:
columns.each {
String searchValue = it.options['searchValue']
String domainName = it.options['domainName']
columns.each {
String orderValue = it.options['order']
String domainName = it.options['domainName']
if (orderValue) {
if (domainName == 'parentName') {
order('parent.name', orderValue)
} else if(domainName == 'customer'){
order('customer.name', orderValue)
} else if (domainName == 'type') {
order('type.name', orderValue)
} else if (domainName == 'devices') {
orderDevice = true
orderDeviceValue = orderValue
} else if (domainName =='tags'){
log.info("sort by tag")
orderTag = true
orderTagValue = orderValue
} else if (domainName == 'description') {
order('description', orderValue)
} else {
order(domainName, orderValue)
}
}
}
这是位置类:
import groovy.transform.ToString
@ToString
class Location implements Comparable<Location> {
Company customer
Location parent
String name
String description
String objectnumber
String address
String zipcode
String province
String city
String country
Long longitude
Long latitude
Integer order
String timezone
AlertConfiguration alertConfiguration
boolean deleted
LocationType type
static mapping = {
order column: '`order`'
name column: '`name`'
version false
}
static constraints = {
parent nullable: true
description nullable: true, maxSize: 65535
objectnumber nullable: true
province nullable: true
city nullable: true
longitude nullable: true
latitude nullable: true
order nullable: true
timezone nullable: true
type nullable: true
alertConfiguration nullable: true
parent nullable: true
address nullable: true
zipcode nullable: true
country nullable: true, maxSize: 3
}
@Override
int compareTo(Location that) {
if (that) {
return this.name.compareTo(that.name)
}
return 0
}
@Override
String toString() {
return "location:"+id
}
}
这是公司课程:
import groovy.transform.ToString
@ToString
class Company {
String name
String address
String zipcode
String province
String city
String country
String phonenumber
String email
String website
String cocnumber
String vatnumber
String logoUrl
boolean deleted
Account account
String contractholder
String initial_contract
static mapping = {
email column: 'emailaddress'
version false
}
static hasMany =[locations: Location]
static constraints = {
address nullable: true
zipcode nullable: true, maxSize: 45
province nullable: true
city nullable: true
country nullable: true, maxSize: 3
phonenumber nullable: true, maxSize: 45
email nullable: true, email:true
website nullable: true
cocnumber nullable: true
vatnumber nullable: true
logoUrl nullable: true, url: true
account nullable: true
contractholder nullable: true
initial_contract nullable: true
}
Company(String name) {
System.out.println("Company constructor " + name)
}
}
我确实有一个与公司类相关联的帐户类,并使用我可以在公司名称上订购,但由于某种原因,按客户名称排序位置会引发错误:
无法解析属性:customer.name of:com.x.Location。 Stacktrace如下:java.lang.reflect.InvocationTargetException:null 在 grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53) 在 grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62) 在 grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745)引起: org.hibernate.QueryException:无法解析属性: customer.name of:com.x.Location at grails.orm.PagedResultList。(PagedResultList.java:43)at grails.orm.HibernateCriteriaBuilder.createPagedResultList(HibernateCriteriaBuilder.java:160) 在 。com.x.location.LocationService $ tt__findAllByAccount(LocationService.groovy:60) 在 grails.transaction.GrailsTransactionTemplate $ 2.doInTransaction(GrailsTransactionTemplate.groovy:96) 在 grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) 在 。com.x.location.LocationBusinessService $ tt__list(LocationBusinessService.groovy:62) 在 grails.transaction.GrailsTransactionTemplate $ 2.doInTransaction(GrailsTransactionTemplate.groovy:96) 在 grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) 在 com.x.location.LocationRestController.list(LocationRestController.groovy:29) ...省略了6个常见帧