gpt4 book ai didi

hibernate - Grails将域类映射到oracle数据库中已经存在的 View

转载 作者:行者123 更新时间:2023-12-02 15:56:02 25 4
gpt4 key购买 nike

我已经创建了一个名为FACULTY_VIEW的数据库 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 )
}

在启动时,我收到此错误消息(这是我期望的):

| Error 2015-11-11 14:58:33,675 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate - Unsuccessful: alter table FACULTY_VIEW add id number(19,0) not null | Error 2015-11-11 14:58:33,677 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate - ORA-00942: table or view does not exist



然后,当我执行搜索时,我得到以下错误信息:

org.hibernate.QueryException: could not resolve property: faculty_last_name of: facultyinformation.FacultyInformation



我当然不打算从该 View 插入或删除,因为我只是在搜索它。

我以一种或另一种方式猜测这是一个休眠问题/配置问题。

任何帮助将不胜感激 :-)

第2部分:
这是我创建 View 的数据库更改日志:
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"
}
}

这是给我错误的 Controller 代码:
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

变得非常沮丧。.我想知道是否更容易避免一起休眠???

最佳答案

根据错误消息的这一部分,数据库连接看不到您的 View :

ORA-00942: table or view does not exist 

显然,请确保该 View 确实存在。

如果该 View 确实存在,请检查数据源配置,并确保它已用于正确的数据库,并且连接参数中指定的用户有权访问该 View 。

关于hibernate - Grails将域类映射到oracle数据库中已经存在的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com