I am trying to save a reservation that has a student id, where Student extends User.
When I save I get the "could not find matching constructor error for java.lang.String(java.lang.Long)."
From what I know, the Long that it's trying to send is the unique id from the Student object. I can't find a workaround, here's my code.
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
When I use reservation1.save() I get an error:
Message: Could not find matching constructor for: java.lang.String(java.lang.Long)
Here is the data that I want to save
//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)
Not sure how complete your example code above is, but I see a couple of things which may or may not be causing the exception you're seeing.
def securityService
(in Reservation) should be transient so gorm doesn't try to persist. BTW - did you mean springSecurityServiceDate().parse("yyyy-MM-dd", '2013-07-23')
)lastUpdated
field should be a Date not String - otherwise you should disable it if you're not using itString reservationId
vs. default id provide by GORM?