2012-10-10 2 views
0

레거시 Oracle 데이터베이스에서 Grails를 사용할 때의 문제점에 직면했습니다. 내가 Grails의 도메인 클래스를 생성레거시 데이터베이스에서 grails 사용

CREATE TABLE "TMS"."TARGETTYPES" 
    ( "TARGETTYPECODE" VARCHAR2(100) NOT NULL ENABLE, 
    "TARGETTYPEDESCR" VARCHAR2(255 CHAR), 
    "ACTIVE" CHAR(1) DEFAULT 'Y' NOT NULL ENABLE, 
    CONSTRAINT "TARGETTYPES_PK" PRIMARY KEY ("TARGETTYPECODE") 
    ) 

:

package tmsconf 

class TargettypesController { 
    def scaffold = true 
} 

응용 프로그램이 성공적으로 시작했습니다

package tmsconf 

class Targettypes { 

    static transients = ['Targettypecode'] 
    void setTargettypecode(String Targettypecode) { 
      id = Targettypecode 
    } 

    String getTargettypecode() { 
      return Targettypecode 
    } 

    String targettypedescr 
    String active 

    static mapping = { 
     table 'TARGETTYPES' 
     version false 
     columns { 
      id generator:'assigned', column:"TARGETTYPECODE", type:'text' 
     } 
    } 

    static constraints = { 
     id() 
     targettypecode(size: 1..100, blank: false) 
     targettypedescr(size: 0..255) 
     active(size: 1..1, blank: false) 
     id(nullable: true) 
    } 
    String toString() { 
     return "${targettypecode}" 
    } 
} 

이 또한 내가 컨트롤러 클래스를 만들었 나는 기본 키 텍스트 열 TARGETTYPECODE와 기존 테이블 TARGETTYPES 있습니다. 내가 링크 tmsconf.TargettypesController 클릭하면

내가 콘솔에 오류가 있습니다

Error 2012-10-10 10:55:37,243 [http-bio-8080-exec-9] ERROR util.JDBCExceptionReporter - ORA-00918: column ambiguously defined 

| Error 2012-10-10 10:55:37,305 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - SQLSyntaxErrorException occurred when processing request: [GET] /TMSConf/targettypes/list 
ORA-00918: column ambiguously defined 
. Stacktrace follows: 
Message: ORA-00918: column ambiguously defined 

    Line | Method 
->> 445 | processError   in oracle.jdbc.driver.T4CTTIoer 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 396 | processError   in  '' 
| 879 | processError . . . . in oracle.jdbc.driver.T4C8Oall 
| 450 | receive    in oracle.jdbc.driver.T4CTTIfun 
| 192 | doRPC . . . . . . . in  '' 
| 531 | doOALL    in oracle.jdbc.driver.T4C8Oall 
| 207 | doOall8 . . . . . . in oracle.jdbc.driver.T4CPreparedStatement 
| 884 | executeForDescribe in  '' 
| 1167 | executeMaybeDescribe in oracle.jdbc.driver.OracleStatement 
| 1289 | doExecuteWithTimeout in  '' 
| 3584 | executeInternal . . in oracle.jdbc.driver.OraclePreparedStatement 
| 3628 | executeQuery   in  '' 
| 1493 | executeQuery . . . . in oracle.jdbc.driver.OraclePreparedStatementWrapper 
|  96 | executeQuery   in org.apache.commons.dbcp.DelegatingPreparedStatement 
|  55 | <init> . . . . . . . in grails.orm.PagedResultList 
|  15 | list     in tmsconf.TargettypesController 
| 186 | doFilter . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter 
|  63 | doFilter    in grails.plugin.cache.web.filter.AbstractFilter 
| 1110 | runWorker . . . . . in java.util.concurrent.ThreadPoolExecutor 
| 603 | run     in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . . . . . . in java.lang.Thread 

이 도와주세요, 내가 잘못

답변

0

이 일을해야 해요 여기서

package tmsconf 

class Targettypes { 

    String targettypecode 
    String targettypedescr 
    String active 

    static mapping = { 
     version false 
     id generator: 'assigned', name: 'targettypecode' 
    } 

    static constraints = { 
     targettypecode(size: 1..100, blank: false) 
     targettypedescr(size: 0..255, nullable: true) 
     active(size: 1..1, blank: false) 
    } 

    String toString() { 
     targettypecode 
    } 
} 

이제 수 mapping 블록에서 name 속성을 사용하십시오. 따라서 ID를 래핑하기 위해 일시적인 get/set 쌍을 만들 필요가 없습니다.

테이블 이름과 열 이름 설정은 어쨌든 사용되는 것으로 설정되었으므로 제거되었으며 type:'text'이 제거되었으므로 Hibernate는 필드 유형을 알고 있으므로 열 유형에 사용할 수 있습니다.

또한 표시된 SQL에 따라 targettypedescrnullable: true을 추가했습니다.

일반적으로 레거시 데이터베이스에 매핑하려는 경우 http://grails.org/doc/latest/ref/Command%20Line/schema-export.html 스크립트를 사용하여 Hibernate에서 테이블이 어떻게 보일 것이라고 생각하는지 확인하십시오. "가깝게"될 때까지 constraintsmapping 블록을 조정하십시오.

+0

대단히 감사합니다. tmsconf.TargettypesController를 클릭하면 Targettype의 레코드 목록이 표시됩니다. 이제 나는 기록을 만들 수 있습니다. 하지만 기존 레코드를 클릭하여 편집 할 때 'ID가 null 인 Targettype을 찾을 수 없습니다.'오류가 발생합니다. – Leonid

관련 문제