我正在尝试保存具有学生ID的预订,其中Student扩展用户。
当我保存时,我得到“找不到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)
答案 0 :(得分:1)
不确定上面的示例代码有多完整,但我看到了一些可能会或可能不会导致您看到的异常的事情。
def securityService
(在预订中)应该是暂时的,因此gorm不会试图坚持下去。顺便说一句 - 你的意思是springSecurityService Date().parse("yyyy-MM-dd", '2013-07-23')
)lastUpdated
字段应为日期而不是字符串 - 否则您应该禁用它'不使用它String reservationId
与默认ID?