belongs to - Grails findBy belongsTo gives JdbcSQLException -
Ask for a system, I had student and user objects, such as:
User {} student {user user // is not frozen steady = [user]} teacher {static belongsTo = [user: user]}
I have written a lot of code against these models , And many dynamic finders in it
def U 1 = new user (). Save (flush: true) New student (user: u1). Savings (flush: true) ... def s = Student.findByUser (springSecurityService.currentUser) //s may be Rick def t = teacher.findbius (spring security service service.) / T can be zero if (s ! = Null) // something with 's' if (t! = Null) // do something with 't' ...
And it all worked fine. But I want to update my domain model to increase user access to students. So I did this:
User {Student student // nullable}
And I will save a user like this:
New User (Student: New Student ()). Savings (flush: true)
But the problem is, when I 'like' as I did above. P>
If Student.findByUser can find such a student, then it works.
But if it should be blank, then instead gives an error.
def s = Student.findByUser (springSecurityService.currentUser)
will result in:
org.h2. Jdbc.jdbcSQLException parameter # 2 is not set; SQL statement: Choose this ID as ID 18_0_, this version as version 18_0_, from the student _ where this_.id =? Limit? [90012-173]
I know that I can use student objects through user objects such as User.student , but I keep it in I want to be able to be like the existing code.
I have seen this thread, and it has a similar problem, but there is no resolution
Is this a bug? What can I do to get around this? Am I not setting up my domain model properly?
Thanks
As an alternative, you isTo you can try this type using
hasOne
.
It is still cascade and seems to fix empty searches.
Comments
Post a Comment