Grails 无效的列名错误

Grails 无效的列名错误,grails,gorm,Grails,Gorm,我正在尝试按瞬态属性排序,但由于SQL错误而失败:列名错误无效 请在下面找到我的代码: 在声明的域类中: static transients = ['sortCandidateLastName'] 我正在尝试执行的查询: 当我尝试在Oracle中运行以下查询时:它运行良好 ( select * from ( select row_.* ,rownum rownum_ from ( select * from booking b where b.marked_deleted='N'

我正在尝试按瞬态属性排序,但由于SQL错误而失败:列名错误无效

请在下面找到我的代码:

在声明的域类中:

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)
普惠制代码:

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

但当Hibernate试图读取它时,它抛出了无效的列名:ResultSet.getIntclazz\uz

,您不能在临时字段上排序。暂时字段没有实际的数据库列!所以你的sql总是会抛出一个错误

瞬态属性不会持久化,因此不可能编写按瞬态属性排序的查询。如果您从查询中检索对象列表,并希望按瞬态属性对它们进行排序,则必须在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 }

我尝试使用jdbcTemplate并提供了所需的功能

代码段: GSP层: 服务层: 希望这对


Cheers

我在我们的项目中有一些使用transient属性的工作示例。但是在这个特定的场景中,查询在hibernate层失败,说列名无效。
<g:sortable property="sortCandidateLastName">
                    <g:message code="booking.alphabetical.label" default="Alphabetical(A-Z)" />
</g:sortable>
if(params.sort == "sortCandidateLastName" )
        {
            bookingCandList= bookingService.orderByCandidateLastName(params.max, params.order,params.offset.toInteger())//Booking.getSortCandidateLastName(params.max, params.order,params.offset.toInteger()) //


        }
def jdbcTemplate

public List orderByCandidateLastName(Integer max, String sortOrder,Integer offset) {
           println  "Inside the getcandidateLastName ${max} :: offset ${offset}"
           def sortedList
           int minRow = offset
           int maxRow = offset+max
           String queryStr =   " select * from " + 
                                   " ( "+ 
                                   " select row_.* " + 
                                   " ,rownum rownum_ " +
                                   " from " +
                                   " ( " +
                                   " select * from booking b where b.item_id= 426 and b.marked_deleted='N' order by " +
                                   " (select c.cand_id from candidate c where b.cand_id = c.cand_id) ${sortOrder} "+
                                   "  ) row_ "+
                                   "where rownum <= ${maxRow}  " +
                                    ") " +
                                    "where rownum > ${minRow}"
           return jdbcTemplate.queryForList(queryStr)
       }
// Place your Spring DSL code here
import org.springframework.jdbc.core.JdbcTemplate

beans = {
..........
    jdbcTemplate(JdbcTemplate) {
        dataSource = ref('dataSource')
     }
}