我已经创建了一个名为FACULTY_VIEW的数据库视图,并希望将grails域类映射到它。 这是域:
class FacultyInformation {
def faculty_pidm
def faculty_person_id
def faculty_first_name
def faculty_last_name
static mapping = {
table 'FACULTY_VIEW'
version false
cache 'read-only',inlcude:'non-lazy'
faculty_pidm column:'FACULTY_PIDM'
faculty_person_id column:'FACULTY_PERSON_ID'
faculty_first_name column:'FACULTY_FIRST_NAME'
faculty_last_name column:'FACULTY_LAST_NAME'
}
}
这是我尝试搜索的域的Controller代码段:
facultySearchList = FacultyInformation.createCriteria().list (max: params.max, offset: params.offset, sort:params.sort, order: params.order) {
ilike("faculty_last_name", searchTerm )
}
启动后,我收到此错误消息(我期望):
|错误2015-11-11 14:58:33,675 [localhost-startStop-1]错误hbm2ddl.SchemaUpdate - 不成功:alter table FACULTY_VIEW add id number(19,0)not null |错误2015-11-11 14:58:33,677 [localhost-startStop-1]错误hbm2ddl.SchemaUpdate - ORA-00942:表 或视图不存在
然后,一旦我执行搜索,我就会收到此错误信息:
org.hibernate.QueryException:无法解析属性: faculty_last_name:facultyinformation.FacultyInformation
我当然不打算在此视图中插入或删除,因为我只是在搜索它。
我以这种或那种方式猜测这是一个休眠问题/配置问题。
非常感谢任何帮助: - )
第2部分: 这是我的db changelog来创建视图:
databaseChangeLog = {
changeSet(author: "jdannucci (generated)", id: "1447432810497-1") {
createView("""
SELECT DISTINCT SIRASGN_PIDM AS faculty_pidm, SPRIDEN_ID AS faculty_person_id, SPRIDEN_FIRST_NAME AS faculty_first_name, SPRIDEN_LAST_NAME AS faculty_last_name
FROM SSBSECT , SCBCRSE, SCRLEVL SC, SIRASGN SA, SPRIDEN
WHERE SSBSECT_TERM_CODE = (SELECT MAX(STVTERM_CODE) FROM STVTERM
WHERE TRUNC(SYSDATE) BETWEEN TRUNC(STVTERM_START_DATE) AND TRUNC(STVTERM_END_DATE))
AND SSBSECT_SUBJ_CODE=SCBCRSE_SUBJ_CODE
AND SSBSECT_CRSE_NUMB=SCBCRSE_CRSE_NUMB
AND SSBSECT_CRN = SIRASGN_CRN
AND SSBSECT_SUBJ_CODE != 'FE'
AND SIRASGN_PRIMARY_IND = 'Y'
AND SSBSECT_TERM_CODE = SIRASGN_TERM_CODE
AND SCRLEVL_LEVL_CODE = '01'
AND SCRLEVL_SUBJ_CODE = SSBSECT_SUBJ_CODE
AND SCRLEVL_CRSE_NUMB = SSBSECT_CRSE_NUMB
AND SCRLEVL_EFF_TERM = (SELECT MAX(SCRLEVL_EFF_TERM)
FROM SCRLEVL
WHERE SCRLEVL_SUBJ_CODE = SC.SCRLEVL_SUBJ_CODE
AND SCRLEVL_CRSE_NUMB = SC. SCRLEVL_CRSE_NUMB
AND SCRLEVL_EFF_TERM <= SSBSECT_TERM_CODE)
AND SCBCRSE_EFF_TERM = (SELECT MAX(SCBCRSE_EFF_TERM)
FROM SATURN.SCBCRSE X
WHERE X.SCBCRSE_SUBJ_CODE=SSBSECT_SUBJ_CODE
AND X.SCBCRSE_CRSE_NUMB=SSBSECT_CRSE_NUMB
AND X.SCBCRSE_EFF_TERM <= SSBSECT_TERM_CODE)
AND SPRIDEN_PIDM = SIRASGN_PIDM
AND SPRIDEN_CHANGE_IND IS NULL
ORDER BY faculty_last_name
""", viewName: 'FACULTY_VIEW')
}
}
这是我的新域名:
package facultyinformation
class FacultyInformation {
def faculty_pidm
def faculty_person_id
def faculty_first_name
def faculty_last_name
static mapping = {
table 'FACULTY_VIEW'
version false
cache 'read-only',inlcude:'non-lazy'
faculty_pidm column:'FACULTY_PIDM'
faculty_person_id column:'FACULTY_PERSON_ID'
faculty_first_name column:'FACULTY_FIRST_NAME'
faculty_last_name column:'FACULTY_LAST_NAME'
}
}
数据源:
development {
dataSource {
dbCreate = "none" // one of 'create', 'create-drop','update'
url = "jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:PPRD"
dialect = "org.hibernate.dialect.Oracle10gDialect"
}
}
这里给出了错误的控制器代码:
facultySearchList = FacultyInformation.createCriteria().list (max: params.max, offset: params.offset, sort:params.sort, order: params.order) {
ilike("faculty_last_name", searchTerm )
}
这是错误:
org.hibernate.QueryException: could not resolve property: faculty_last_name of: facultyinformation.FacultyInformation
非常沮丧..我想知道是否更容易避免一起休眠???
答案 0 :(得分:0)
根据错误消息的这一部分,数据库连接看不到您的视图:
ORA-00942: table or view does not exist
显然,请确保视图确实存在。
如果视图确实存在,请检查数据源配置并确保它正在使用到正确的数据库,并且连接参数中指定的用户可以访问该视图。
答案 1 :(得分:0)
我通过显式执行SQL来创建db-migration插件的一些视图,即使用sql('''CREATE OR REPLACE VIEW
而不是createView("""
此外,您还希望通过实施DdlFilterConfiguration
来排除GORM表更新中的观点,如Burt Beckwith的演示文稿中所述:http://www.slideshare.net/gr8conf/gorm-burt-beckwith2011