我正在尝试保存具有学生ID的预订,学生将在其中扩展用户。
保存时,出现“找不到java.lang.String(java.lang.Long)的匹配构造函数错误”。
据我所知,它试图发送的Long是来自Student对象的唯一ID。我找不到解决方法,这是我的代码。
class User {
static hasMany = [reservations:Reservation, students:Student, faculty:Faculty]
String username
String password
String firstName
String lastName
String phoneNumber
String emailAddress
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
class Student extends User{
static belongsTo = [users:User]
static hasMany = [reservations:Reservation]
String studentId
class Reservation {
def securityService
Student student
String reservationId
String lastUpdated
String lastUpdatedBy
String startDate
String endDate
当我使用Reservation1.save()时出现错误:
Message: Could not find matching constructor for: java.lang.String(java.lang.Long)
这是我要保存的数据
//UserData
def user1 = Student.findByUsername('bobby') ?: new Student(username: 'bobby',
enabled: true, password: 'pass', firstName: 'robert', lastName:'plant',
metroStateStudentId: '012345670', phoneNumber: '0123456789',
//Reservation Data
def reservation1 = Reservation.findByReservationId('123456') ?: new Reservation(reservationId:'123456',
student: user1,startDate:'2013-07-23', endDate:'2013-07-27',lastUpdatedBy:'bobby')
reservation1.save(flush: true, failOnError: true)
最佳答案
不确定上面的示例代码的完整性如何,但是我看到了一些可能会或可能不会导致您看到的异常的事情。
def securityService
(在保留中)应该是 transient 的,因此gorm不会尝试持久。顺便说一句-您的意思是springSecurityService 例如
Date().parse("yyyy-MM-dd", '2013-07-23')
)lastUpdated
字段应为日期而不是字符串-否则,如果您不使用它,则应禁用它String reservationId
和默认ID? 关于grails - GORM组合保存错误,找不到与以下对象匹配的构造函数:java.lang.String(java.lang.Long),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17796246/