0

我有一个父类:

class A{
      Integer a1
      Integer a2

      static mapping = {
           table 'table_A'
           version true
    tablePerHierarchy true
    discriminator column:[name:'typeOfChild',length:8]
    id generator:'sequence', params:[sequence:'TEMP_SEQ']
    columns{
        id                  column: 'ID'
        version             column: 'VERSION'
        a1                  column: 'A1'
        b1                  column: 'A2'
}

 class Child1 extends A{

       static mapping = {
       discriminator value: "child1"
       }        
}
 class Child2 extends A{

       static mapping = {
       discriminator value: "child2"
       }        
}

因此,如上所示,类 Child1 和 Child2 扩展了类 A,鉴别器列将用于区分实例。

数据库表如下:

create table table_A(
ID integer(2),
A1 integer(2),
A2 integer(2),
typeOfChild varchar2(8),
primary key(ID));

现在我有另一个类 ContainerClass 如下:

class ContainerClass{
....
List child1 = new ArrayList()
List child2 = new ArrayList()
....

static hasMany[] = [child1:Child1,child2:Child2]

static mapping = {
...
child1 cascade : "all-delete-orphan"
child2 cascade : "all-delete-orphan"
}

 def getChild1List() {  
    return LazyList.decorate(child1, FactoryUtils.instantiateFactory(Child1.class))
}
def getChild2List() {
    return LazyList.decorate(child2, FactoryUtils.instantiateFactory(Child2.class))
}

 }

现在,当我创建一个 ContainerClass 对象并且在数据库中还有需要获取的数据时,LazyList.decorate 函数无法初始化子对象列表。我得到一个例外如下:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not initialize a collection: [###################################]
    at java.lang.Thread.run(Thread.java:619)
    Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection:          
    Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:9
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:9
    ... 1 more

有什么不同的方式可以让这些带有grails鉴别器参数的子类和父类中的整个表映射?

4

1 回答 1

0

ORA-00942 描述可以在这里看到: http ://www.dbadvices.com/ora-00942-table-view-exist-fixed/

于 2014-11-16T05:41:22.740 回答