我正在尝试保存具有学生 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)