Hibernate Grails GORM SQL绑定参数失败,带validate()
我对Grails2.2.3和验证域对象有一个奇怪的问题;我有两个数据库转储,据我所知是相同的 更新记录并调用validate时出错,错误如下:Hibernate Grails GORM SQL绑定参数失败,带validate(),hibernate,grails,gorm,Hibernate,Grails,Gorm,我对Grails2.2.3和验证域对象有一个奇怪的问题;我有两个数据库转储,据我所知是相同的 更新记录并调用validate时出错,错误如下: util.JDBCExceptionReporter - No value specified for parameter 1 我已经打开了HibernateSQL日志记录和绑定日志记录 对于不工作的数据库,获取以下日志输出: 2014-10-22 12:28:06,163 [http-bio-8080-exec-3] DEBUG hibernate
util.JDBCExceptionReporter - No value specified for parameter 1
我已经打开了HibernateSQL日志记录和绑定日志记录
对于不工作的数据库,获取以下日志输出:
2014-10-22 12:28:06,163 [http-bio-8080-exec-3] DEBUG hibernate.SQL - select this_.id as id0_0_, this_.version as version0_0_, this_.birthday as birthday0_0_, this_.cellular as cellular0_0_, this_.city as city0_0_, this_.country as country0_0_, this_.date_created as date7_0_0_, this_.description as descript8_0_0_, this_.email as email0_0_, this_.first_name as first10_0_0_, this_.gender as gender0_0_, this_.house_number as house12_0_0_, this_.identifier as identifier0_0_, this_.is_child as is14_0_0_, this_.is_host as is15_0_0_, this_.is_press as is16_0_0_, this_.is_visitor as is17_0_0_, this_.last_name as last18_0_0_, this_.last_updated as last19_0_0_, this_.latitude as latitude0_0_, this_.longitude as longitude0_0_, this_.phone as phone0_0_, this_.picture as picture0_0_, this_.postal_code as postal24_0_0_, this_.state as state0_0_, this_.street as street0_0_ from person this_ where this_.email=?
2014-10-22 12:28:06,164 [http-bio-8080-exec-3] TRACE sql.BasicBinder - binding parameter [1] as [VARCHAR] - joe@example.net
2014-10-22 12:28:06,168 [http-bio-8080-exec-3] TRACE sql.BasicExtractor - found [1414] as column [id0_0_]
2014-10-22 12:28:06,169 [http-bio-8080-exec-3] DEBUG hibernate.SQL - select this_.id as id0_0_, this_.version as version0_0_, this_.birthday as birthday0_0_, this_.cellular as cellular0_0_, this_.city as city0_0_, this_.country as country0_0_, this_.date_created as date7_0_0_, this_.description as descript8_0_0_, this_.email as email0_0_, this_.first_name as first10_0_0_, this_.gender as gender0_0_, this_.house_number as house12_0_0_, this_.identifier as identifier0_0_, this_.is_child as is14_0_0_, this_.is_host as is15_0_0_, this_.is_press as is16_0_0_, this_.is_visitor as is17_0_0_, this_.last_name as last18_0_0_, this_.last_updated as last19_0_0_, this_.latitude as latitude0_0_, this_.longitude as longitude0_0_, this_.phone as phone0_0_, this_.picture as picture0_0_, this_.postal_code as postal24_0_0_, this_.state as state0_0_, this_.street as street0_0_ from person this_ where this_.id=?
2014-10-22 12:28:06,172 [http-bio-8080-exec-3] ERROR util.JDBCExceptionReporter - No value specified for parameter 1
通过工作数据库,我得到以下信息:
2014-10-22 12:23:24,476 [http-bio-8080-exec-3] DEBUG hibernate.SQL - select this_.id as id7_0_, this_.version as version7_0_, this_.birthday as birthday7_0_, this_.cellular as cellular7_0_, this_.city as city7_0_, this_.country as country7_0_, this_.date_created as date7_7_0_, this_.description as descript8_7_0_, this_.email as email7_0_, this_.first_name as first10_7_0_, this_.gender as gender7_0_, this_.house_number as house12_7_0_, this_.identifier as identifier7_0_, this_.is_child as is14_7_0_, this_.is_host as is15_7_0_, this_.is_press as is16_7_0_, this_.is_visitor as is17_7_0_, this_.last_name as last18_7_0_, this_.last_updated as last19_7_0_, this_.latitude as latitude7_0_, this_.longitude as longitude7_0_, this_.phone as phone7_0_, this_.picture as picture7_0_, this_.postal_code as postal24_7_0_, this_.state as state7_0_, this_.street as street7_0_ from person this_ where this_.email=?
2014-10-22 12:23:24,477 [http-bio-8080-exec-3] TRACE sql.BasicBinder - binding parameter [1] as [VARCHAR] - joe@example.net
2014-10-22 12:23:24,480 [http-bio-8080-exec-3] TRACE sql.BasicExtractor - found [1414] as column [id7_0_]
2014-10-22 12:23:24,499 [http-bio-8080-exec-3] DEBUG hibernate.SQL - select this_.id as id7_0_, this_.version as version7_0_, this_.birthday as birthday7_0_, this_.cellular as cellular7_0_, this_.city as city7_0_, this_.country as country7_0_, this_.date_created as date7_7_0_, this_.description as descript8_7_0_, this_.email as email7_0_, this_.first_name as first10_7_0_, this_.gender as gender7_0_, this_.house_number as house12_7_0_, this_.identifier as identifier7_0_, this_.is_child as is14_7_0_, this_.is_host as is15_7_0_, this_.is_press as is16_7_0_, this_.is_visitor as is17_7_0_, this_.last_name as last18_7_0_, this_.last_updated as last19_7_0_, this_.latitude as latitude7_0_, this_.longitude as longitude7_0_, this_.phone as phone7_0_, this_.picture as picture7_0_, this_.postal_code as postal24_7_0_, this_.state as state7_0_, this_.street as street7_0_ from person this_ where this_.email=?
2014-10-22 12:23:24,500 [http-bio-8080-exec-3] TRACE sql.BasicBinder - binding parameter [1] as [VARCHAR] - joe@example.net
2014-10-22 12:23:24,503 [http-bio-8080-exec-3] TRACE sql.BasicExtractor - found [1414] as column [id7_0_]
不同之处在于,工作版本两次查询以电子邮件地址作为搜索参数的条目,而损坏的版本第二次尝试按ID进行查询,但无法绑定ID
有没有关于在哪里查找错误的建议?如何更好地调试它
谢谢
迈克尔
编辑:
GORM类Person.groovy
class Person {
enum Gender {
MALE,FEMALE,FAMILY,NO_GENDER
}
Date dateCreated
Date lastUpdated
Set identifiers
String firstName
String lastName
String email
String phone
String cellular
String street
String houseNumber
String postalCode
String city
String state
String country
Date birthday
Gender gender = Gender.NO_GENDER
Double latitude
Double longitude
String picture
String description
static hasOne = [paymentInformation: PaymentInformation]
static hasMany = [identifiers: String, children: ChildParent, parents: ChildParent, guests: ChildHost, visitorCalls: VisitorCall, comments: PersonComment, flags: PersonFlag, sentMessages: Message, receivedMessages: Message, romperRoomBookings: RomperRoomBooking, payments: Payment]
static mappedBy = [children: 'parent', parents: 'child', sentMessages: 'sender']
static constraints = {
firstName nullable: false, blank: false
lastName nullable: false, blank: false
email nullable: false, blank: false, email: true, unique: true
phone nullable: true, blank: false
cellular nullable: true, blank: false
street nullable: true, blank: false
houseNumber nullable: true, blank: false
postalCode nullable: true, blank: false
city nullable: true, blank: false
state nullable: true, blank: false
country nullable: true, blank: false
latitude nullable: true
longitude nullable: true
birthday nullable: true
gender nullable: true
picture nullable: true, blank: false
description nullable: true, blank: false
paymentInformation nullable: true, unique: true
}
static mapping = {
description type: 'text'
paymentInformation lazy: false
flags lazy: false
}
}
发生错误的控制器是
def person = Person.get(id)
if (person) {
def personInput = JSON.parse(request)
if (personInput) {
def gecodingAddress = googleGeocodingService.geocode(personInput.street,personInput.houseNumber,personInput.postalCode,personInput.city,personInput.state ? personInput.state : null,personInput.country ? personInput.country : "Germany")
if (gecodingAddress) {
person.firstName = personInput.firstName
person.lastName = personInput.lastName
person.street = gecodingAddress.street
person.houseNumber = gecodingAddress.houseNumber
person.postalCode = gecodingAddress.postalCode
person.city = gecodingAddress.city
person.state = gecodingAddress.state
person.country = gecodingAddress.country
person.latitude = gecodingAddress.lat
person.longitude = gecodingAddress.lon
person.email = JSONObject.NULL.equals(personInput.email) || personInput.email?.isEmpty() ? null : personInput.email
person.phone = JSONObject.NULL.equals(personInput.phone) || personInput.phone?.isEmpty() ? null : personInput.phone
person.cellular = JSONObject.NULL.equals(personInput.cellular) || personInput.cellular?.isEmpty() ? null : personInput.cellular
person.dateCreated = new Date(personInput.dateCreated)
if (person.validate()) {
if (person.save(flush: true)) {
render(person as JSON)
}
else {
render(status: 500)
}
}
else {
log.warn("validate failed!")
person.errors.allErrors.each {
log.warn(it)
}
render(status: 400)
}
}
else {
render(status: 500)
}
}
else {
render(status: 400)
}
}
else {
render(status: 404)
}
person.validate调用失败,它甚至无法到达person.save我添加了GORM类以及来自控制器的相关部分。你是说我有两个数据库转储,据我所知完全相同?一个来自我的开发系统,另一个来自远程实例,它是使用我的开发机器上的mysql转储设置的;为了将两个系统之间的差异降到最低,我再次在远程机器上进行了mysql转储,并在本地机器上创建了另一个数据库;结果是,只有来自本地机器的原始版本有效,而从远程机器重新导入的版本无效,并导致上述错误。