我有一个父类:
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,并且将使用discriminator列来区分实例。
数据库表如下:
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函数无法初始化子对象的List。我得到如下例外:
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 discriminator参数和父类中的整个表映射是否有任何不同的方式?