我试图将所有PostOrder拉出到子实例存在的地方
我的域名如下:
class PostOrder {
String pOrder
Date dateCreated
Picture picture
Post posts
Video video
static hasMany = [children : Child]
}
我试图用来获取对象的方法是:
def getAllInOrder(Child child){
def json = PostOrder.findAllByChildren(child, sort: 'dateCreated', order: 'desc') as JSON
return json
}
我只是从这里获得sql异常。 任何想法?
这些也是我的例外:
util.JDBCExceptionReporter No value specified for parameter 1
errors.GrailsExceptionResolver SQLException occurred when processing request: [GET] /FYP/profile/appPosts - parameters:
child: 1
No value specified for parameter 1. Stacktrace follows:
java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2595)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2571)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2497)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2251)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall(GormStaticApi.groovy:105)
at com.fyp.timeline.ProfileController$$ENmIB8q0.getAllInOrder(ProfileController.groovy:636)
at com.fyp.timeline.ProfileController$$ENmIB8q0.appPosts(ProfileController.groovy:624)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
答案 0 :(得分:1)
尝试
PostOrder.findAllByChildren(child, [sort: 'dateCreated', order: 'desc'])
虽然我认为这不会完全解决您的问题,因为在这种情况下,孩子应该是一个列表。试试这个:
PostOrder.all.findAll{it.children.contains(child)}
似乎应该有更好的方法来做到这一点,也许其他人可以响个不停。