我正在尝试按瞬时属性进行排序,但失败,并显示SQL错误:无效的列名error。

请在我的代码下面找到:

在声明的域类中:

static transients = ['sortCandidateLastName']

查询我要执行的查询:

当我尝试在Oracle中运行以下查询时:它运行良好
( select * from  (  select row_.*  ,rownum rownum_  from  (  select * from booking b where b.marked_deleted='N' order by  (select c.cand_id from candidate c where b.cand_id = c.cand_id) asc   ) row_ where rownum <= 15  ) where rownum > 0)

GSP代码:
<g:sortableColumn property="sortCandidateLastName" title="Sort By Candidate Last Name" />

但是,当Hibernate尝试读取它时,它将抛出无效的列名:ResultSet.getInt(clazz_)

最佳答案

transient 属性不会保留,因此无法编写按 transient 属性排序的查询。如果您从查询中检索对象列表并想按瞬时属性对其进行排序,则必须使用Groovy代码进行处理,例如

// an example domain class with a transient property
class Book {
  private static Long SEQUENCE_GENERATOR = 0

  String isbn
  String title
  Long sequence = ++SEQUENCE_GENERATOR

  static transients = ['sequence']
}

// get a list of books from the DB and sort by the transient property
def books = Book.list()
books.sort { it.sequence }

关于grails - 无效的列名错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22959181/

10-10 15:12